From 31a4d21c41a6c05ad3ce5783c6e0a0284a26b25f Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 16 Mar 2024 21:09:00 +0100 Subject: [PATCH] Change the way flood_sleep_threshold behaves --- client/src/telethon/_impl/client/client/net.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/client/src/telethon/_impl/client/client/net.py b/client/src/telethon/_impl/client/client/net.py index 3b1b24c2..abd88f84 100644 --- a/client/src/telethon/_impl/client/client/net.py +++ b/client/src/telethon/_impl/client/client/net.py @@ -53,7 +53,7 @@ class Config: lang_code: str = "en" catch_up: bool = False datacenter: Optional[DataCenter] = None - flood_sleep_threshold: Optional[int] = 60 + flood_sleep_threshold: int = 60 update_queue_limit: Optional[int] = None @@ -245,8 +245,7 @@ async def invoke_request( lock: asyncio.Lock, request: Request[Return], ) -> Return: - slept_flood = False - sleep_thresh = client._config.flood_sleep_threshold or 0 + sleep_thresh = client._config.flood_sleep_threshold rx = sender.enqueue(request) while True: while not rx.done(): @@ -255,14 +254,9 @@ async def invoke_request( response = rx.result() break except RpcError as e: - if ( - e.code == 420 - and e.value is not None - and not slept_flood - and e.value < sleep_thresh - ): + if e.code == 420 and e.value is not None and e.value < sleep_thresh: await asyncio.sleep(e.value) - slept_flood = True + sleep_thresh -= e.value rx = sender.enqueue(request) continue else: