chore: use running event loop in async helpers (#821)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user