fix(project): stabilize python3 tests and app shutdown

Use python3/venv consistently for local test execution and
make package discovery deterministic for pytest.

Also migrate FastAPI shutdown handling to lifespan to remove
deprecation warnings while preserving cleanup behavior.
This commit is contained in:
truetype committed 2026-02-06 11:22:57 +01:00
1 parent 572d551a2c
commit b2ee220783
4 files changed
+29 -8

No files matched your search

+13 -6
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import dataclasses
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import HTMLResponse
@@ -13,12 +14,23 @@ from app.services import PortScanner
from app.storage import Storage
from app.tunnel_manager import TunnelManager
app = FastAPI(title="Gradio Tunnel Dashboard")
policy = TunnelPolicy.load()
storage = Storage.from_env()
scanner = PortScanner(policy=policy, storage=storage)
manager = TunnelManager(storage=storage)
@asynccontextmanager
async def lifespan(_: FastAPI):
try:
yield
finally:
manager.shutdown()
storage.close()
app = FastAPI(title="Gradio Tunnel Dashboard", lifespan=lifespan)
app.mount("/static", StaticFiles(directory="app/static"), name="static")
templates = Jinja2Templates(directory="app/templates")
@@ -99,8 +111,3 @@ async def stop_tunnel(port: int) -> dict[str, bool]:
raise HTTPException(status_code=404, detail="Tunnel not running.")
return {"stopped": True}
@app.on_event("shutdown")
def shutdown_event() -> None:
manager.shutdown()
storage.close()