Some adjustments with compute WebSocket handling. Ref https://github.com/GNS3/gns3-server/issues/1564

This commit is contained in:
grossmj
2019-04-14 16:48:12 +07:00
parent 6db8cecda5
commit 6dc58b28fd
3 changed files with 43 additions and 18 deletions

View File

@ -21,6 +21,9 @@ from aiohttp.web import WebSocketResponse
from gns3server.web.route import Route
from gns3server.compute.notification_manager import NotificationManager
import logging
log = logging.getLogger(__name__)
async def process_websocket(ws):
"""
@ -44,7 +47,7 @@ class NotificationHandler:
request.app['websockets'].add(ws)
asyncio.ensure_future(process_websocket(ws))
log.info("New client has connected to compute WebSocket")
try:
with notifications.queue() as queue:
while True:
@ -53,6 +56,7 @@ class NotificationHandler:
break
await ws.send_str(notification)
finally:
log.info("Client has disconnected from compute WebSocket")
if not ws.closed:
await ws.close()
request.app['websockets'].discard(ws)