fix: defer terminal manager idle check until event loop is running
TerminalManager was trying to create an asyncio task at module import time, but no event loop exists yet during import. This caused RuntimeError on startup. Changes: - _start_idle_check() now checks if event loop is running before creating task - If no loop exists, silently skips (will be started lazily) - Added lazy start call in get_or_create_session() when websocket connects
This commit is contained in:
@@ -23,8 +23,14 @@ class TerminalManager:
|
||||
|
||||
def _start_idle_check(self) -> None:
|
||||
"""Start the idle timeout background task."""
|
||||
if self._idle_check_task is None or self._idle_check_task.done():
|
||||
self._idle_check_task = asyncio.create_task(self._idle_check_loop())
|
||||
if self._idle_check_task is not None and not self._idle_check_task.done():
|
||||
return
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
self._idle_check_task = loop.create_task(self._idle_check_loop())
|
||||
except RuntimeError:
|
||||
# No event loop running yet, will be started lazily
|
||||
pass
|
||||
|
||||
async def _idle_check_loop(self) -> None:
|
||||
"""Periodically check for idle sessions and clean them up."""
|
||||
@@ -54,6 +60,9 @@ class TerminalManager:
|
||||
container_id: str,
|
||||
) -> TerminalSession:
|
||||
"""Get existing session or create a new one."""
|
||||
# Ensure idle check is running (lazy start)
|
||||
self._start_idle_check()
|
||||
|
||||
instance_id_str = str(instance_id)
|
||||
|
||||
# Check for existing session
|
||||
|
||||
Reference in New Issue
Block a user