refac
This commit is contained in:
1 parent
0103d7e82c
commit
7eaecbad5a
2 files changed
+16
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
@@ -68,12 +69,18 @@ def serve(
|
|||||||
import open_webui.main # noqa: F401
|
import open_webui.main # noqa: F401
|
||||||
from open_webui.env import UVICORN_WORKERS # Import the workers setting
|
from open_webui.env import UVICORN_WORKERS # Import the workers setting
|
||||||
|
|
||||||
|
# On Windows, uvicorn's default loop factory hardcodes ProactorEventLoop,
|
||||||
|
# which is incompatible with psycopg v3 async. Setting loop='none' lets
|
||||||
|
# asyncio.run() respect the WindowsSelectorEventLoopPolicy set in db.py.
|
||||||
|
loop = 'none' if sys.platform == 'win32' else 'auto'
|
||||||
|
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
'open_webui.main:app',
|
'open_webui.main:app',
|
||||||
host=host,
|
host=host,
|
||||||
port=port,
|
port=port,
|
||||||
forwarded_allow_ips='*',
|
forwarded_allow_ips='*',
|
||||||
workers=UVICORN_WORKERS,
|
workers=UVICORN_WORKERS,
|
||||||
|
loop=loop,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from contextlib import asynccontextmanager, contextmanager
|
from contextlib import asynccontextmanager, contextmanager
|
||||||
@@ -332,6 +333,14 @@ get_db = contextmanager(get_session)
|
|||||||
# all work without any stripping or translation.
|
# all work without any stripping or translation.
|
||||||
ASYNC_SQLALCHEMY_DATABASE_URL = _make_async_url(SQLALCHEMY_DATABASE_URL)
|
ASYNC_SQLALCHEMY_DATABASE_URL = _make_async_url(SQLALCHEMY_DATABASE_URL)
|
||||||
|
|
||||||
|
# psycopg v3 cannot run in async mode under Windows' default
|
||||||
|
# ProactorEventLoop — switch to SelectorEventLoop before creating
|
||||||
|
# the async engine. This runs at import time, which is early enough
|
||||||
|
# to cover every entry point (workers, reload, direct invocations).
|
||||||
|
if sys.platform == 'win32' and _is_postgres_url(DATABASE_URL):
|
||||||
|
import asyncio
|
||||||
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
|
|
||||||
if 'sqlite' in ASYNC_SQLALCHEMY_DATABASE_URL:
|
if 'sqlite' in ASYNC_SQLALCHEMY_DATABASE_URL:
|
||||||
# Generous default — async coroutines + no session sharing = high connection demand.
|
# Generous default — async coroutines + no session sharing = high connection demand.
|
||||||
_sqlite_pool_size = DATABASE_POOL_SIZE if isinstance(DATABASE_POOL_SIZE, int) and DATABASE_POOL_SIZE > 0 else 512
|
_sqlite_pool_size = DATABASE_POOL_SIZE if isinstance(DATABASE_POOL_SIZE, int) and DATABASE_POOL_SIZE > 0 else 512
|
||||||
|
|||||||
Reference in new issue
Block a user