fix: Windows Ctrl+C 快速关闭服务
This commit is contained in:
16
web/app.py
16
web/app.py
@@ -242,7 +242,21 @@ async def get_stats():
|
|||||||
|
|
||||||
def run_web():
|
def run_web():
|
||||||
"""启动 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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user