Add telnet server

This commit is contained in:
Ian Renton
2026-09-11 15:55:57 +01:00
parent 04f5df5260
commit 5e56cd3b19
32 changed files with 222 additions and 35 deletions
+41
View File
@@ -0,0 +1,41 @@
import logging
import threading
from tornado.ioloop import IOLoop
logger = logging.getLogger(__name__)
class SSEBroadcaster:
"""Bridge between DataStore listener callbacks (which fire on provider threads) to Tornado's async SSE handlers
(which live on the IOLoop thread) to avoid any interdependency between them."""
def __init__(self):
self._handlers = set()
self._lock = threading.Lock()
self._loop = None
def bind_to_web_server_loop(self):
self._loop = IOLoop.current()
def register(self, handler):
with self._lock:
self._handlers.add(handler)
def unregister(self, handler):
with self._lock:
self._handlers.discard(handler)
def publish(self, value):
self._loop.add_callback(self._broadcast, value)
def _broadcast(self, value):
with self._lock:
handlers = list(self._handlers)
for handler in handlers:
try:
handler.callback(value)
except Exception:
# Connection probably dropped, ignore and de-register the handler to stop getting future items.
logger.debug("Failed to push to an SSE client; dropping it")
self.unregister(handler)