mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Improve flood wait log message
This commit is contained in:
parent
2ffd1e8e7c
commit
cca50ef842
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import datetime
|
||||
import itertools
|
||||
import time
|
||||
import typing
|
||||
|
@ -14,6 +15,16 @@ if typing.TYPE_CHECKING:
|
|||
from .telegramclient import TelegramClient
|
||||
|
||||
|
||||
def _fmt_flood(delay, request, *, early=False, td=datetime.timedelta):
|
||||
return (
|
||||
'Sleeping%s for %ds (%s) on %s flood wait',
|
||||
' early' if early else '',
|
||||
delay,
|
||||
td(seconds=delay),
|
||||
request.__class__.__name__
|
||||
)
|
||||
|
||||
|
||||
class UserMethods:
|
||||
async def __call__(self: 'TelegramClient', request, ordered=False):
|
||||
requests = (request if utils.is_list_like(request) else (request,))
|
||||
|
@ -29,8 +40,7 @@ class UserMethods:
|
|||
if diff <= 3: # Flood waits below 3 seconds are "ignored"
|
||||
self._flood_waited_requests.pop(r.CONSTRUCTOR_ID, None)
|
||||
elif diff <= self.flood_sleep_threshold:
|
||||
self._log[__name__].info(
|
||||
'Sleeping early for %ds on flood wait', diff)
|
||||
self._log[__name__].info(*_fmt_flood(diff, r, early=True))
|
||||
await asyncio.sleep(diff, loop=self._loop)
|
||||
self._flood_waited_requests.pop(r.CONSTRUCTOR_ID, None)
|
||||
else:
|
||||
|
@ -80,8 +90,7 @@ class UserMethods:
|
|||
[request.CONSTRUCTOR_ID] = time.time() + e.seconds
|
||||
|
||||
if e.seconds <= self.flood_sleep_threshold:
|
||||
self._log[__name__].info('Sleeping for %ds on flood wait',
|
||||
e.seconds)
|
||||
self._log[__name__].info(*_fmt_flood(e.seconds, request))
|
||||
await asyncio.sleep(e.seconds, loop=self._loop)
|
||||
else:
|
||||
raise
|
||||
|
|
Loading…
Reference in New Issue
Block a user