From d27ad50c0ea215772558a242cedae0a02ad2b280 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Mon, 7 Jun 2021 13:34:06 -0400 Subject: [PATCH] don't exit when client closes --- hbd | 10 +++++++--- wstest.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hbd b/hbd index 36621d0..4e19e8e 100755 --- a/hbd +++ b/hbd @@ -864,13 +864,17 @@ def websocketupdater(): def msg_to_websockets(typ: str, msg: str): jmsg = json.dumps({'type': typ, 'data': msg}) + to_close = [] for ws in ws_connections: try: asyncio.run(ws.send(jmsg)) - except Exception as e: - print("ws.send exception: %s" % e) - exit(1) + except Exception: + to_close.append(ws) + print("ws.send exception: closed") + for ws in to_close: + ws.close() + del ws_connections[ws] # # Main # diff --git a/wstest.py b/wstest.py index 88cfdd3..4b7743b 100644 --- a/wstest.py +++ b/wstest.py @@ -2,7 +2,7 @@ import asyncio import websockets async def hello(): - uri = "ws://w02:50005/messages" + uri = "ws://localhost:50005/messages" async with websockets.connect(uri) as websocket: name = "Andreas"