Skip to content

Self-hosted AI workspace.

Python

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

Rolly Calma86efc8808e62
diff --git a/routes/embedding_routes.py b/routes/embedding_routes.py
index bcf63d618..3b6b09012 100644
--- a/routes/embedding_routes.py
+++ b/routes/embedding_routes.py
@@ -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,
diff --git a/routes/shell_routes.py b/routes/shell_routes.py
index d0cd4b28f..1fdd610be 100644
--- a/routes/shell_routes.py
+++ b/routes/shell_routes.py
@@ -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)
diff --git a/src/research_handler.py b/src/research_handler.py
index 5550bdef4..7719e9db8 100644
--- a/src/research_handler.py
+++ b/src/research_handler.py
@@ -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
)
diff --git a/src/task_scheduler.py b/src/task_scheduler.py
index 3916c7bb6..bf2dfe3fc 100644
--- a/src/task_scheduler.py
+++ b/src/task_scheduler.py
@@ -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