mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-10 22:43:29 +00:00
Merge 066adb3fc9 into 1dcbfd47fb
This commit is contained in:
commit
1d696b53a0
1 changed files with 9 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ import sys
|
|||
import time
|
||||
import random
|
||||
import re
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
|
|
@ -646,10 +647,15 @@ async def lifespan(app: FastAPI):
|
|||
if app.state.redis is not None:
|
||||
app.state.redis_task_command_listener = asyncio.create_task(redis_task_command_listener(app))
|
||||
|
||||
executor = None
|
||||
|
||||
if THREAD_POOL_SIZE and THREAD_POOL_SIZE > 0:
|
||||
limiter = anyio.to_thread.current_default_thread_limiter()
|
||||
limiter.total_tokens = THREAD_POOL_SIZE
|
||||
|
||||
executor = ThreadPoolExecutor(max_workers=THREAD_POOL_SIZE)
|
||||
app.state.main_loop.set_default_executor(executor)
|
||||
|
||||
asyncio.create_task(periodic_usage_pool_cleanup())
|
||||
asyncio.create_task(periodic_session_pool_cleanup())
|
||||
|
||||
|
|
@ -713,6 +719,9 @@ async def lifespan(app: FastAPI):
|
|||
|
||||
yield
|
||||
|
||||
if executor is not None:
|
||||
executor.shutdown()
|
||||
|
||||
if hasattr(app.state, 'redis_task_command_listener'):
|
||||
app.state.redis_task_command_listener.cancel()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue