From 57dd733f6708c150f924d5d454704ee7d44360e9 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Thu, 16 Apr 2026 12:07:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Windows=20Ctrl+C=20=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/app.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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__":