mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Fix disconnect and reconnect for exported senders (#53)
This commit is contained in:
parent
097d1669b2
commit
6b4f2abb96
|
@ -51,7 +51,11 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
self.found_media = set()
|
self.found_media = set()
|
||||||
|
|
||||||
print('Connecting to Telegram servers...')
|
print('Connecting to Telegram servers...')
|
||||||
self.connect()
|
if not self.connect():
|
||||||
|
print('Initial connection failed. Retrying...')
|
||||||
|
if not self.connect():
|
||||||
|
print('Could not connect to Telegram servers.')
|
||||||
|
return
|
||||||
|
|
||||||
# Then, ensure we're authorized and have access
|
# Then, ensure we're authorized and have access
|
||||||
if not self.is_user_authorized():
|
if not self.is_user_authorized():
|
||||||
|
|
|
@ -147,7 +147,8 @@ class TelegramClient:
|
||||||
self._setup_ping_thread()
|
self._setup_ping_thread()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except RPCError as error:
|
except (RPCError, ConnectionError) as error:
|
||||||
|
# Probably errors from the previous session, ignore them
|
||||||
self._logger.warning('Could not stabilise initial connection: {}'
|
self._logger.warning('Could not stabilise initial connection: {}'
|
||||||
.format(error))
|
.format(error))
|
||||||
return False
|
return False
|
||||||
|
@ -163,7 +164,7 @@ class TelegramClient:
|
||||||
self.transport = None
|
self.transport = None
|
||||||
|
|
||||||
# Also disconnect all the cached senders
|
# Also disconnect all the cached senders
|
||||||
for sender in self._cached_senders:
|
for sender in self._cached_senders.values():
|
||||||
sender.disconnect()
|
sender.disconnect()
|
||||||
|
|
||||||
self._cached_senders.clear()
|
self._cached_senders.clear()
|
||||||
|
@ -196,7 +197,7 @@ class TelegramClient:
|
||||||
if not self.dc_options:
|
if not self.dc_options:
|
||||||
raise ConnectionError(
|
raise ConnectionError(
|
||||||
'Cannot determine the required data center IP address. '
|
'Cannot determine the required data center IP address. '
|
||||||
'Stabilise an initial connection first.')
|
'Stabilise a successful initial connection first.')
|
||||||
|
|
||||||
return next(dc for dc in self.dc_options if dc.id == dc_id)
|
return next(dc for dc in self.dc_options if dc.id == dc_id)
|
||||||
|
|
||||||
|
@ -218,8 +219,8 @@ class TelegramClient:
|
||||||
|
|
||||||
if sender and session:
|
if sender and session:
|
||||||
if init_connection:
|
if init_connection:
|
||||||
# TODO reconnect
|
sender.disconnect()
|
||||||
pass
|
sender.connect()
|
||||||
|
|
||||||
return sender
|
return sender
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user