small fix to websocketchannel and relay
This commit is contained in:
parent
875e9ab447
commit
ce43fa5f43
@ -77,21 +77,24 @@ class WebSocketChannel:
|
|||||||
# until self.drain_timeout for the relay to drain the outgoing queue
|
# until self.drain_timeout for the relay to drain the outgoing queue
|
||||||
# We can't use asyncio.wait_for here because the queue may have been created with a
|
# We can't use asyncio.wait_for here because the queue may have been created with a
|
||||||
# different eventloop
|
# different eventloop
|
||||||
start = time.time()
|
if not self.is_closed():
|
||||||
while self.queue.full():
|
start = time.time()
|
||||||
await asyncio.sleep(1)
|
while self.queue.full():
|
||||||
if (time.time() - start) > self.drain_timeout:
|
await asyncio.sleep(1)
|
||||||
|
if (time.time() - start) > self.drain_timeout:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# If for some reason the queue is still full, just return False
|
||||||
|
try:
|
||||||
|
self.queue.put_nowait(data)
|
||||||
|
except asyncio.QueueFull:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If for some reason the queue is still full, just return False
|
# If we got here everything is ok
|
||||||
try:
|
return True
|
||||||
self.queue.put_nowait(data)
|
else:
|
||||||
except asyncio.QueueFull:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# If we got here everything is ok
|
|
||||||
return True
|
|
||||||
|
|
||||||
async def recv(self):
|
async def recv(self):
|
||||||
"""
|
"""
|
||||||
Receive data on the wrapped websocket
|
Receive data on the wrapped websocket
|
||||||
@ -109,14 +112,14 @@ class WebSocketChannel:
|
|||||||
Close the WebSocketChannel
|
Close the WebSocketChannel
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self._closed.set()
|
||||||
|
self._relay_task.cancel()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.raw_websocket.close()
|
await self.raw_websocket.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._closed.set()
|
|
||||||
self._relay_task.cancel()
|
|
||||||
|
|
||||||
def is_closed(self) -> bool:
|
def is_closed(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Closed flag
|
Closed flag
|
||||||
|
Loading…
Reference in New Issue
Block a user