From 4ad699dbe6d50644a9e564d652a11f648565e1d2 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 9 Jun 2025 13:06:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BC=98=E9=9B=85=E5=81=9C=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 1081ac03..5012d410 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ import multiprocessing import os +import signal import sys import threading @@ -21,7 +22,7 @@ from app.db.init import init_db, update_db # uvicorn服务 Server = uvicorn.Server(Config(app, host=settings.HOST, port=settings.PORT, reload=settings.DEV, workers=multiprocessing.cpu_count(), - timeout_graceful_shutdown=5)) + timeout_graceful_shutdown=30)) def start_tray(): @@ -70,7 +71,19 @@ def start_tray(): threading.Thread(target=TrayIcon.run, daemon=True).start() +def signal_handler(signum, frame): + """ + 信号处理函数,用于优雅停止服务 + """ + print(f"收到信号 {signum},开始优雅停止服务...") + Server.should_exit = True + + if __name__ == '__main__': + # 注册信号处理器 + signal.signal(signal.SIGTERM, signal_handler) + signal.signal(signal.SIGINT, signal_handler) + # 启动托盘 start_tray() # 初始化数据库