diff --git a/web/app.py b/web/app.py index 29e8982..490373b 100644 --- a/web/app.py +++ b/web/app.py @@ -242,7 +242,21 @@ async def get_stats(): def run_web(): """启动 Web 服务""" - uvicorn.run(app, host=WEB_HOST, port=WEB_PORT) + import uvicorn + import signal + import sys + + config = uvicorn.Config(app, host=WEB_HOST, port=WEB_PORT, log_level="info") + server = uvicorn.Server(config) + + def signal_handler(sig, frame): + print("\nShutting down...") + server.should_exit = True + sys.exit(0) + + signal.signal(signal.SIGINT, signal_handler) + + server.run() if __name__ == "__main__":