don't exit when client closes
This commit is contained in:
@@ -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
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user