Fix: define _run_tasks_with_optional_timeout before use; tidy run_webtransport block

This commit is contained in:
Vladyslav Doloman
2025-10-08 00:29:18 +03:00
parent 1bd4d9eac7
commit 99e818e0fd

15
run.py
View File

@@ -6,6 +6,21 @@ from server.server import GameServer
from server.config import ServerConfig
async def _run_tasks_with_optional_timeout(tasks):
"""Await tasks, optionally honoring RUN_SECONDS env var to cancel after a timeout."""
timeout_s = os.environ.get("RUN_SECONDS")
if not timeout_s:
await asyncio.gather(*tasks)
return
try:
await asyncio.wait_for(asyncio.gather(*tasks), timeout=float(timeout_s))
except asyncio.TimeoutError:
logging.info("Timeout reached (RUN_SECONDS=%s); stopping server tasks...", timeout_s)
for t in tasks:
t.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
async def run_in_memory():
from server.transport import InMemoryTransport
cfg = ServerConfig()