mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-11 11:30:39 +00:00
Avoid explicitly passing the loop to asyncio
This behaviour is deprecated and will be removed in future versions of Python. Technically, it could be considered a bug (invalid usage causing different behaviour from the expected one), and in practice it should not break much code (because .get_event_loop() would likely be the same event loop anyway).
This commit is contained in:
@@ -378,7 +378,7 @@ class DialogMethods:
|
||||
entities = [await self.get_input_entity(entity)]
|
||||
else:
|
||||
entities = await asyncio.gather(
|
||||
*(self.get_input_entity(x) for x in entity), loop=self.loop)
|
||||
*(self.get_input_entity(x) for x in entity))
|
||||
|
||||
if folder is None:
|
||||
raise ValueError('You must specify a folder')
|
||||
|
||||
@@ -180,7 +180,8 @@ class TelegramBaseClient(abc.ABC):
|
||||
Defaults to `lang_code`.
|
||||
|
||||
loop (`asyncio.AbstractEventLoop`, optional):
|
||||
Asyncio event loop to use. Defaults to `asyncio.get_event_loop()`
|
||||
Asyncio event loop to use. Defaults to `asyncio.get_event_loop()`.
|
||||
This argument is ignored.
|
||||
|
||||
base_logger (`str` | `logging.Logger`, optional):
|
||||
Base logger name or instance to use.
|
||||
@@ -227,7 +228,7 @@ class TelegramBaseClient(abc.ABC):
|
||||
"Refer to telethon.rtfd.io for more information.")
|
||||
|
||||
self._use_ipv6 = use_ipv6
|
||||
self._loop = loop or asyncio.get_event_loop()
|
||||
self._loop = asyncio.get_event_loop()
|
||||
|
||||
if isinstance(base_logger, str):
|
||||
base_logger = logging.getLogger(base_logger)
|
||||
@@ -334,7 +335,7 @@ class TelegramBaseClient(abc.ABC):
|
||||
)
|
||||
|
||||
self._sender = MTProtoSender(
|
||||
self.session.auth_key, self._loop,
|
||||
self.session.auth_key,
|
||||
loggers=self._log,
|
||||
retries=self._connection_retries,
|
||||
delay=self._retry_delay,
|
||||
@@ -350,15 +351,15 @@ class TelegramBaseClient(abc.ABC):
|
||||
|
||||
# Cache ``{dc_id: (_ExportState, MTProtoSender)}`` for all borrowed senders
|
||||
self._borrowed_senders = {}
|
||||
self._borrow_sender_lock = asyncio.Lock(loop=self._loop)
|
||||
self._borrow_sender_lock = asyncio.Lock()
|
||||
|
||||
self._updates_handle = None
|
||||
self._last_request = time.time()
|
||||
self._channel_pts = {}
|
||||
|
||||
if sequential_updates:
|
||||
self._updates_queue = asyncio.Queue(loop=self._loop)
|
||||
self._dispatching_updates_queue = asyncio.Event(loop=self._loop)
|
||||
self._updates_queue = asyncio.Queue()
|
||||
self._dispatching_updates_queue = asyncio.Event()
|
||||
else:
|
||||
# Use a set of pending instead of a queue so we can properly
|
||||
# terminate all pending updates on disconnect.
|
||||
@@ -481,7 +482,6 @@ class TelegramBaseClient(abc.ABC):
|
||||
self.session.server_address,
|
||||
self.session.port,
|
||||
self.session.dc_id,
|
||||
loop=self._loop,
|
||||
loggers=self._log,
|
||||
proxy=self._proxy
|
||||
)):
|
||||
@@ -556,7 +556,7 @@ class TelegramBaseClient(abc.ABC):
|
||||
for task in self._updates_queue:
|
||||
task.cancel()
|
||||
|
||||
await asyncio.wait(self._updates_queue, loop=self._loop)
|
||||
await asyncio.wait(self._updates_queue)
|
||||
self._updates_queue.clear()
|
||||
|
||||
pts, date = self._state_cache[None]
|
||||
@@ -639,12 +639,11 @@ class TelegramBaseClient(abc.ABC):
|
||||
#
|
||||
# If one were to do that, Telegram would reset the connection
|
||||
# with no further clues.
|
||||
sender = MTProtoSender(None, self._loop, loggers=self._log)
|
||||
sender = MTProtoSender(None, loggers=self._log)
|
||||
await sender.connect(self._connection(
|
||||
dc.ip_address,
|
||||
dc.port,
|
||||
dc.id,
|
||||
loop=self._loop,
|
||||
loggers=self._log,
|
||||
proxy=self._proxy
|
||||
))
|
||||
@@ -680,7 +679,6 @@ class TelegramBaseClient(abc.ABC):
|
||||
dc.ip_address,
|
||||
dc.port,
|
||||
dc.id,
|
||||
loop=self._loop,
|
||||
loggers=self._log,
|
||||
proxy=self._proxy
|
||||
))
|
||||
|
||||
@@ -326,7 +326,7 @@ class UpdateMethods:
|
||||
while self.is_connected():
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
self.disconnected, timeout=60, loop=self._loop
|
||||
self.disconnected, timeout=60
|
||||
)
|
||||
continue # We actually just want to act upon timeout
|
||||
except asyncio.TimeoutError:
|
||||
|
||||
@@ -44,7 +44,7 @@ class UserMethods:
|
||||
self._flood_waited_requests.pop(r.CONSTRUCTOR_ID, None)
|
||||
elif diff <= self.flood_sleep_threshold:
|
||||
self._log[__name__].info(*_fmt_flood(diff, r, early=True))
|
||||
await asyncio.sleep(diff, loop=self._loop)
|
||||
await asyncio.sleep(diff)
|
||||
self._flood_waited_requests.pop(r.CONSTRUCTOR_ID, None)
|
||||
else:
|
||||
raise errors.FloodWaitError(request=r, capture=diff)
|
||||
@@ -99,7 +99,7 @@ class UserMethods:
|
||||
|
||||
if e.seconds <= self.flood_sleep_threshold:
|
||||
self._log[__name__].info(*_fmt_flood(e.seconds, request))
|
||||
await asyncio.sleep(e.seconds, loop=self._loop)
|
||||
await asyncio.sleep(e.seconds)
|
||||
else:
|
||||
raise
|
||||
except (errors.PhoneMigrateError, errors.NetworkMigrateError,
|
||||
|
||||
Reference in New Issue
Block a user