fix(server): close http listener cleanly on shutdown
This commit is contained in:
13
src/main.py
13
src/main.py
@@ -288,7 +288,7 @@ async def main(port=80):
|
|||||||
def settings_page(request):
|
def settings_page(request):
|
||||||
"""Serve the settings page."""
|
"""Serve the settings page."""
|
||||||
return send_file('templates/settings.html')
|
return send_file('templates/settings.html')
|
||||||
|
|
||||||
# Favicon: avoid 404 in browser console (no file needed)
|
# Favicon: avoid 404 in browser console (no file needed)
|
||||||
@app.route('/favicon.ico')
|
@app.route('/favicon.ico')
|
||||||
def favicon(request):
|
def favicon(request):
|
||||||
@@ -387,6 +387,17 @@ async def main(port=80):
|
|||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
srv = getattr(app, "server", None)
|
||||||
|
if srv is not None:
|
||||||
|
try:
|
||||||
|
srv.close()
|
||||||
|
await srv.wait_closed()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
app.server = None
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
if shutdown_handlers_registered:
|
if shutdown_handlers_registered:
|
||||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user