[fix] meh, sanic isn't ready for websockets 7.0

This commit is contained in:
Laurent Peuch 2019-04-01 23:07:27 +02:00
parent 102dec555f
commit 7ba3449fb5

19
run.py
View file

@ -22,6 +22,7 @@ import aiohttp
import aiofiles import aiofiles
from websockets.exceptions import ConnectionClosed from websockets.exceptions import ConnectionClosed
from websockets import WebSocketCommonProtocol
from sanic import Sanic, response from sanic import Sanic, response
from sanic.exceptions import NotFound from sanic.exceptions import NotFound
@ -103,6 +104,24 @@ subscriptions = defaultdict(list)
jobs_in_memory_state = {} jobs_in_memory_state = {}
@asyncio.coroutine
def wait_closed(self):
"""
Wait until the connection is closed.
This is identical to :attr:`closed`, except it can be awaited.
This can make it easier to handle connection termination, regardless
of its cause, in tasks that interact with the WebSocket connection.
"""
yield from asyncio.shield(self.connection_lost_waiter)
# this is a backport of websockets 7.0 which sanic doesn't support yet
WebSocketCommonProtocol.wait_closed = wait_closed
def reset_pending_jobs(): def reset_pending_jobs():
Job.update(state="scheduled", log="").where(Job.state == "running").execute() Job.update(state="scheduled", log="").where(Job.state == "running").execute()