don't exit when client closes

This commit is contained in:
2021-06-07 13:34:06 -04:00
parent 8a4042f95f
commit d27ad50c0e
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -864,13 +864,17 @@ def websocketupdater():
def msg_to_websockets(typ: str, msg: str): def msg_to_websockets(typ: str, msg: str):
jmsg = json.dumps({'type': typ, 'data': msg}) jmsg = json.dumps({'type': typ, 'data': msg})
to_close = []
for ws in ws_connections: for ws in ws_connections:
try: try:
asyncio.run(ws.send(jmsg)) asyncio.run(ws.send(jmsg))
except Exception as e: except Exception:
print("ws.send exception: %s" % e) to_close.append(ws)
exit(1) print("ws.send exception: closed")
for ws in to_close:
ws.close()
del ws_connections[ws]
# #
# Main # Main
# #
+1 -1
View File
@@ -2,7 +2,7 @@ import asyncio
import websockets import websockets
async def hello(): async def hello():
uri = "ws://w02:50005/messages" uri = "ws://localhost:50005/messages"
async with websockets.connect(uri) as websocket: async with websockets.connect(uri) as websocket:
name = "Andreas" name = "Andreas"