Fix: define _run_tasks_with_optional_timeout before use; tidy run_webtransport block
This commit is contained in:
15
run.py
15
run.py
@@ -6,6 +6,21 @@ from server.server import GameServer
|
|||||||
from server.config import ServerConfig
|
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():
|
async def run_in_memory():
|
||||||
from server.transport import InMemoryTransport
|
from server.transport import InMemoryTransport
|
||||||
cfg = ServerConfig()
|
cfg = ServerConfig()
|
||||||
|
|||||||
Reference in New Issue
Block a user