mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 10:15:27 -04:00
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
|
_downloading[model_name] = True
|
||||||
try:
|
try:
|
||||||
# Run in thread to not block the event loop
|
# Run in thread to not block the event loop
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
cache = _cache_dir()
|
cache = _cache_dir()
|
||||||
await loop.run_in_executor(
|
await loop.run_in_executor(
|
||||||
None,
|
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"
|
yield f"data: {json.dumps({'exit_code': -1, 'error': PTY_UNSUPPORTED_ERROR})}\n\n"
|
||||||
return
|
return
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
master_fd, slave_fd = pty.openpty()
|
master_fd, slave_fd = pty.openpty()
|
||||||
|
|
||||||
# Set master to non-blocking
|
# Set master to non-blocking
|
||||||
@@ -782,10 +782,11 @@ def setup_shell_routes() -> APIRouter:
|
|||||||
]
|
]
|
||||||
|
|
||||||
finished = 0
|
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:
|
while finished < 2:
|
||||||
if deadline:
|
if deadline:
|
||||||
remaining = deadline - asyncio.get_event_loop().time()
|
remaining = deadline - loop.time()
|
||||||
if remaining <= 0:
|
if remaining <= 0:
|
||||||
raise asyncio.TimeoutError()
|
raise asyncio.TimeoutError()
|
||||||
wait = min(remaining, 2.0)
|
wait = min(remaining, 2.0)
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ class ResearchHandler:
|
|||||||
try:
|
try:
|
||||||
import asyncio
|
import asyncio
|
||||||
logger.info("Falling back to legacy ResearchOrchestrator...")
|
logger.info("Falling back to legacy ResearchOrchestrator...")
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
result = await loop.run_in_executor(
|
result = await loop.run_in_executor(
|
||||||
None, self._legacy_engine.start_research, query, max_time
|
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
|
pending = fut
|
||||||
owner = False
|
owner = False
|
||||||
else:
|
else:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
fut = loop.create_future()
|
fut = loop.create_future()
|
||||||
_shared_cache_pending[key] = fut
|
_shared_cache_pending[key] = fut
|
||||||
pending = fut
|
pending = fut
|
||||||
|
|||||||
Reference in New Issue
Block a user