From 08b6ea0e17412a1a308db5b5a9c89dd9649c69af Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 8 May 2025 20:47:41 +0400 Subject: [PATCH] refac --- backend/open_webui/config.py | 11 ++++++++++- backend/open_webui/main.py | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index c53eed953..8075bf123 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -1262,7 +1262,16 @@ ENABLE_USER_WEBHOOKS = PersistentConfig( ) # FastAPI / AnyIO settings -THREAD_POOL_SIZE = int(os.getenv("THREAD_POOL_SIZE", "0")) +THREAD_POOL_SIZE = os.getenv("THREAD_POOL_SIZE", None) + +if THREAD_POOL_SIZE is not None and isinstance(THREAD_POOL_SIZE, str): + try: + THREAD_POOL_SIZE = int(THREAD_POOL_SIZE) + except ValueError: + log.warning( + f"THREAD_POOL_SIZE is not a valid integer: {THREAD_POOL_SIZE}. Defaulting to None." + ) + THREAD_POOL_SIZE = None def validate_cors_origins(origins): diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 135e28e91..becacf4dd 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -461,10 +461,9 @@ async def lifespan(app: FastAPI): log.info("Installing external dependencies of functions and tools...") install_tool_and_function_dependencies() - pool_size = THREAD_POOL_SIZE - if pool_size and pool_size > 0: + if THREAD_POOL_SIZE and THREAD_POOL_SIZE > 0: limiter = anyio.to_thread.current_default_thread_limiter() - limiter.total_tokens = pool_size + limiter.total_tokens = THREAD_POOL_SIZE asyncio.create_task(periodic_usage_pool_cleanup())