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

@@ -43,14 +43,16 @@ async def main_start(app, loop):
app.ctx.threadexec = ThreadPoolExecutor(
max_workers=workers, thread_name_prefix="cista-ioworker"
)
await watching.start(app, loop)
watching.start(app, loop)
@app.after_server_stop
# Sanic sometimes fails to execute after_server_stop, so we do it before instead (potentially interrupting handlers)
@app.before_server_stop
async def main_stop(app, loop):
quit.set()
await watching.stop(app, loop)
watching.stop(app)
app.ctx.threadexec.shutdown()
logger.debug("Cista worker threads all finished")
@app.on_request