chore: use running event loop in async helpers (#821)

This commit is contained in:
Rolly Calma
2026-06-02 11:28:05 +08:00
committed by GitHub
parent c99193041a
commit 32efeeb3a2
4 changed files with 7 additions and 6 deletions

View File

@@ -160,7 +160,7 @@ def setup_embedding_routes():
_downloading[model_name] = True
try:
# Run in thread to not block the event loop
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
cache = _cache_dir()
await loop.run_in_executor(
None,

View File

@@ -363,7 +363,7 @@ async def _generate_pty(cmd: str, timeout: int, request: Request):
yield f"data: {json.dumps({'exit_code': -1, 'error': PTY_UNSUPPORTED_ERROR})}\n\n"
return
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
master_fd, slave_fd = pty.openpty()
# Set master to non-blocking
@@ -782,10 +782,11 @@ def setup_shell_routes() -> APIRouter:
]
finished = 0
deadline = (asyncio.get_event_loop().time() + timeout) if timeout else None
loop = asyncio.get_running_loop()
deadline = (loop.time() + timeout) if timeout else None
while finished < 2:
if deadline:
remaining = deadline - asyncio.get_event_loop().time()
remaining = deadline - loop.time()
if remaining <= 0:
raise asyncio.TimeoutError()
wait = min(remaining, 2.0)

View File

@@ -750,7 +750,7 @@ class ResearchHandler:
try:
import asyncio
logger.info("Falling back to legacy ResearchOrchestrator...")
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
result = await loop.run_in_executor(
None, self._legacy_engine.start_research, query, max_time
)

View File

@@ -38,7 +38,7 @@ async def _cached(key: Tuple, ttl: float, fetch: Callable[[], Awaitable[Any]]) -
pending = fut
owner = False
else:
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
fut = loop.create_future()
_shared_cache_pending[key] = fut
pending = fut