Fix issue with SSE queues getting lost #3

This commit is contained in:
Ian Renton
2025-12-23 21:26:39 +00:00
parent 86beb27ebf
commit 6116d19580
3 changed files with 25 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import asyncio
import logging
import os
import tornado
@@ -98,6 +99,22 @@ class WebServer:
# Clean up any SSE queues that are growing too large; probably their client disconnected and we didn't catch it
# properly for some reason.
def clean_up_sse_queues(self):
self.sse_spot_queues = [q for q in self.sse_spot_queues if not q.full()]
self.sse_alert_queues = [q for q in self.sse_alert_queues if not q.full()]
for q in self.sse_spot_queues:
try:
if q.full():
logging.warn("A full SSE spot queue was found, presumably because the client disconnected strangely. It has been removed.")
self.sse_spot_queues.remove(q)
q.empty()
except:
# Probably got deleted already on another thread
pass
for q in self.sse_alert_queues:
try:
if q.full():
logging.warn("A full SSE alert queue was found, presumably because the client disconnected strangely. It has been removed.")
self.sse_alert_queues.remove(q)
q.empty()
except:
# Probably got deleted already on another thread
pass
pass