Fix installation with Python 3.7. Fixes #1414.

Fix deprecated use of aiohttp.Timeout. Fixes #1296.
Use "async with" with aiohttp.ClientSession().
Make sure websocket connections are properly closed, see https://docs.aiohttp.org/en/stable/web_advanced.html#graceful-shutdown
Finish to drop Python 3.4.
This commit is contained in:
grossmj committed 2018-10-16 15:56:06 +07:00
1 parent 8217f65e97
commit 86f87aec74
11 files changed
+124 -155

No files matched your search

@@ -69,14 +69,17 @@ class NotificationHandler:
ws = aiohttp.web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].add(ws)
asyncio.ensure_future(process_websocket(ws))
with controller.notification.controller_queue() as queue:
while True:
try:
notification = await queue.get_json(5)
if ws.closed:
break
await ws.send_str(notification)
except asyncio.futures.CancelledError:
break
if ws.closed:
break
ws.send_str(notification)
finally:
request.app['websockets'].discard(ws)
return ws
@@ -261,17 +261,19 @@ class ProjectHandler:
ws = aiohttp.web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].add(ws)
asyncio.ensure_future(process_websocket(ws))
with controller.notification.project_queue(project) as queue:
while True:
try:
notification = await queue.get_json(5)
except asyncio.futures.CancelledError as e:
if ws.closed:
break
await ws.send_str(notification)
except asyncio.futures.CancelledError:
break
if ws.closed:
break
ws.send_str(notification)
finally:
request.app['websockets'].discard(ws)
if project.auto_close:
# To avoid trouble with client connecting disconnecting we sleep few seconds before checking