Cleaner server shutdowns:

- Remove a workaround for Sanic server not always terminating cleanly
- Terminate worker threads before server stop
- Silent closing of watching WebSocket attempted to open while shutting down
This commit is contained in:
Leo Vasanko
2025-08-17 07:21:03 -06:00
parent 26addb2f7b
commit 33db2c01b4
4 changed files with 12 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
import os
import re
import signal
from pathlib import Path
from sanic import Sanic
@@ -12,14 +11,6 @@ def run(*, dev=False):
"""Run Sanic main process that spawns worker processes to serve HTTP requests."""
from .app import app
# Set up immediate exit on Ctrl+C for faster termination
def signal_handler(signum, frame):
print("\nReceived interrupt signal, exiting immediately...")
os._exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
url, opts = parse_listen(config.config.listen)
# Silence Sanic's warning about running in production rather than debug
os.environ["SANIC_IGNORE_PRODUCTION_WARNING"] = "1"