mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 11:10:18 +03:00
commit fixes
This commit is contained in:
parent
73dd8fa69e
commit
aa498882f8
|
@ -51,7 +51,7 @@ class UserMethods:
|
||||||
|
|
||||||
request_index = 0
|
request_index = 0
|
||||||
self._last_request = time.time()
|
self._last_request = time.time()
|
||||||
attempt = 0
|
|
||||||
for attempt in retry_range(self._request_retries):
|
for attempt in retry_range(self._request_retries):
|
||||||
try:
|
try:
|
||||||
future = sender.send(request, ordered=ordered)
|
future = sender.send(request, ordered=ordered)
|
||||||
|
|
|
@ -95,16 +95,19 @@ def strip_text(text, entities):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
def retry_range(retries, reconnect=False):
|
def retry_range(retries, force_retry=True):
|
||||||
"""
|
"""
|
||||||
Generates an integer sequence starting from 1. If `retries` is
|
Generates an integer sequence starting from 1. If `retries` is
|
||||||
not a zero or a positive integer value, the sequence will be
|
not a zero or a positive integer value, the sequence will be
|
||||||
infinite, otherwise it will end at `retries + 1`.
|
infinite, otherwise it will end at `retries + 1`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if retries == 0 and not reconnect:
|
# We need atleast one iteration even if the retries are 0
|
||||||
|
# when force_retry is True.
|
||||||
|
if retries == 0 and force_retry:
|
||||||
yield 1
|
yield 1
|
||||||
|
|
||||||
|
# If retries are non 0 then itetrate
|
||||||
attempt = 0
|
attempt = 0
|
||||||
while attempt != retries:
|
while attempt != retries:
|
||||||
yield 1 + attempt
|
yield 1 + attempt
|
||||||
|
|
|
@ -217,7 +217,7 @@ class MTProtoSender:
|
||||||
self._log.info('Connecting to %s...', self._connection)
|
self._log.info('Connecting to %s...', self._connection)
|
||||||
|
|
||||||
connected = False
|
connected = False
|
||||||
attempt = 0
|
|
||||||
for attempt in retry_range(self._retries):
|
for attempt in retry_range(self._retries):
|
||||||
if not connected:
|
if not connected:
|
||||||
connected = await self._try_connect(attempt)
|
connected = await self._try_connect(attempt)
|
||||||
|
@ -360,22 +360,24 @@ class MTProtoSender:
|
||||||
retries = self._retries if self._auto_reconnect else 0
|
retries = self._retries if self._auto_reconnect else 0
|
||||||
|
|
||||||
attempt = 0
|
attempt = 0
|
||||||
for attempt in retry_range(retries,reconnect=True):
|
for attempt in retry_range(retries, False):
|
||||||
try:
|
try:
|
||||||
await self._connect()
|
await self._connect()
|
||||||
except (IOError, asyncio.TimeoutError) as e:
|
except (IOError, asyncio.TimeoutError) as e:
|
||||||
last_error = e
|
last_error = e
|
||||||
self._log.info('Failed reconnection attempt %d with %s',
|
self._log.info('Failed reconnection attempt %d with %s',
|
||||||
attempt, e.__class__.__name__)
|
attempt, e.__class__.__name__)
|
||||||
await asyncio.sleep(self._delay)
|
await asyncio.sleep(self._delay)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
last_error = e
|
last_error = e
|
||||||
self._log.exception('Unexpected exception reconnecting on '
|
self._log.exception('Unexpected exception reconnecting on '
|
||||||
'attempt %d', attempt)
|
'attempt %d', attempt)
|
||||||
|
|
||||||
await asyncio.sleep(self._delay)
|
await asyncio.sleep(self._delay)
|
||||||
else:
|
else:
|
||||||
self._send_queue.extend(self._pending_state.values())
|
self._send_queue.extend(self._pending_state.values())
|
||||||
self._pending_state.clear()
|
self._pending_state.clear()
|
||||||
|
|
||||||
if self._auto_reconnect_callback:
|
if self._auto_reconnect_callback:
|
||||||
asyncio.get_event_loop().create_task(self._auto_reconnect_callback())
|
asyncio.get_event_loop().create_task(self._auto_reconnect_callback())
|
||||||
|
|
||||||
|
@ -384,7 +386,6 @@ class MTProtoSender:
|
||||||
self._log.error('Automatic reconnection failed %d time(s)', attempt)
|
self._log.error('Automatic reconnection failed %d time(s)', attempt)
|
||||||
await self._disconnect(error=last_error.with_traceback(None))
|
await self._disconnect(error=last_error.with_traceback(None))
|
||||||
|
|
||||||
|
|
||||||
def _start_reconnect(self, error):
|
def _start_reconnect(self, error):
|
||||||
"""Starts a reconnection in the background."""
|
"""Starts a reconnection in the background."""
|
||||||
if self._user_connected and not self._reconnecting:
|
if self._user_connected and not self._reconnecting:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user