websockets: minor fixes

When a websocket is closed, set "is_closed" to True in the on_closed handler.   When closing all websockets, iterate through a list of values.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-02-24 07:28:32 -05:00
parent 87e136003f
commit ab6ed40bcb
1 changed files with 2 additions and 1 deletions

View File

@ -252,7 +252,7 @@ class WebsocketManager:
async def close(self):
async with self.ws_lock:
for ws in self.websockets.values():
for ws in list(self.websockets.values()):
ws.close()
self.websockets = {}
@ -297,6 +297,7 @@ class WebSocket(WebSocketHandler):
f"Error sending data over websocket: {self.uid}")
def on_close(self):
self.is_closed = True
io_loop = IOLoop.current()
io_loop.spawn_callback(self.wsm.remove_websocket, self)