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

@@ -119,8 +119,12 @@ async def watch(req, ws):
# Send updates
while True:
await ws.send(await q.get())
except RuntimeError as e:
if str(e) == "cannot schedule new futures after shutdown":
return # Server shutting down, drop the WebSocket
raise
finally:
del watching.pubsub[uuid]
watching.pubsub.pop(uuid, None) # Remove whether it got added yet or not
def subscribe(uuid, ws):