mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix 优雅停止
This commit is contained in:
+14
-1
@@ -1,5 +1,6 @@
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ from app.db.init import init_db, update_db
|
|||||||
# uvicorn服务
|
# uvicorn服务
|
||||||
Server = uvicorn.Server(Config(app, host=settings.HOST, port=settings.PORT,
|
Server = uvicorn.Server(Config(app, host=settings.HOST, port=settings.PORT,
|
||||||
reload=settings.DEV, workers=multiprocessing.cpu_count(),
|
reload=settings.DEV, workers=multiprocessing.cpu_count(),
|
||||||
timeout_graceful_shutdown=5))
|
timeout_graceful_shutdown=30))
|
||||||
|
|
||||||
|
|
||||||
def start_tray():
|
def start_tray():
|
||||||
@@ -70,7 +71,19 @@ def start_tray():
|
|||||||
threading.Thread(target=TrayIcon.run, daemon=True).start()
|
threading.Thread(target=TrayIcon.run, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(signum, frame):
|
||||||
|
"""
|
||||||
|
信号处理函数,用于优雅停止服务
|
||||||
|
"""
|
||||||
|
print(f"收到信号 {signum},开始优雅停止服务...")
|
||||||
|
Server.should_exit = True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
# 注册信号处理器
|
||||||
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
# 启动托盘
|
# 启动托盘
|
||||||
start_tray()
|
start_tray()
|
||||||
# 初始化数据库
|
# 初始化数据库
|
||||||
|
|||||||
Reference in New Issue
Block a user