Reverts "[utils] WebSocketsWrapper: Ignore warnings at websockets instantiation"

The warning should not be suppressed. We need to address it
pull/3560/head
pukkandan 3 years ago
parent 69b59b4b4b
commit 9cd080508d
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

@ -36,7 +36,6 @@ import tempfile
import time import time
import traceback import traceback
import urllib.parse import urllib.parse
import warnings
import xml.etree.ElementTree import xml.etree.ElementTree
import zlib import zlib
@ -5222,23 +5221,18 @@ class WebSocketsWrapper():
pool = None pool = None
def __init__(self, url, headers=None, connect=True): def __init__(self, url, headers=None, connect=True):
self.loop = asyncio.new_event_loop() self.loop = asyncio.events.new_event_loop()
with warnings.catch_warnings(): # XXX: "loop" is deprecated
warnings.simplefilter("ignore") self.conn = websockets.connect(
# https://github.com/aaugustin/websockets/blob/9c87d43f1d7bbf6847350087aae74fd35f73a642/src/websockets/legacy/client.py#L480 url, extra_headers=headers, ping_interval=None,
# the reason to keep giving `loop` parameter: we aren't in async function close_timeout=float('inf'), loop=self.loop, ping_timeout=float('inf'))
self.conn = websockets.connect(
url, extra_headers=headers, ping_interval=None,
close_timeout=float('inf'), loop=self.loop, ping_timeout=float('inf'))
if connect: if connect:
self.__enter__() self.__enter__()
atexit.register(self.__exit__, None, None, None) atexit.register(self.__exit__, None, None, None)
def __enter__(self): def __enter__(self):
if not self.pool: if not self.pool:
with warnings.catch_warnings(): self.pool = self.run_with_loop(self.conn.__aenter__(), self.loop)
warnings.simplefilter("ignore")
self.pool = self.run_with_loop(self.conn.__aenter__(), self.loop)
return self return self
def send(self, *args): def send(self, *args):
@ -5258,7 +5252,7 @@ class WebSocketsWrapper():
# for contributors: If there's any new library using asyncio needs to be run in non-async, move these function out of this class # for contributors: If there's any new library using asyncio needs to be run in non-async, move these function out of this class
@staticmethod @staticmethod
def run_with_loop(main, loop): def run_with_loop(main, loop):
if not asyncio.iscoroutine(main): if not asyncio.coroutines.iscoroutine(main):
raise ValueError(f'a coroutine was expected, got {main!r}') raise ValueError(f'a coroutine was expected, got {main!r}')
try: try:
@ -5278,6 +5272,7 @@ class WebSocketsWrapper():
for task in to_cancel: for task in to_cancel:
task.cancel() task.cancel()
# XXX: "loop" is removed in python 3.10+
loop.run_until_complete( loop.run_until_complete(
asyncio.tasks.gather(*to_cancel, loop=loop, return_exceptions=True)) asyncio.tasks.gather(*to_cancel, loop=loop, return_exceptions=True))

Loading…
Cancel
Save