mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Don't error when calling disconnect after logout
This commit is contained in:
parent
4f51604def
commit
83f13da420
|
@ -620,6 +620,7 @@ class AuthMethods:
|
|||
|
||||
await self.disconnect()
|
||||
self.session.delete()
|
||||
self.session = None
|
||||
return True
|
||||
|
||||
async def edit_2fa(
|
||||
|
|
|
@ -523,6 +523,9 @@ class TelegramBaseClient(abc.ABC):
|
|||
except OSError:
|
||||
print('Failed to connect')
|
||||
"""
|
||||
if self.session is None:
|
||||
raise ValueError('TelegramClient instance cannot be reused after logging out')
|
||||
|
||||
if not await self._sender.connect(self._connection(
|
||||
self.session.server_address,
|
||||
self.session.port,
|
||||
|
@ -603,6 +606,9 @@ class TelegramBaseClient(abc.ABC):
|
|||
# You don't need to use this if you used "with client"
|
||||
await client.disconnect()
|
||||
"""
|
||||
if self.session is None:
|
||||
return # already logged out and disconnected
|
||||
|
||||
if self.loop.is_running():
|
||||
# Disconnect may be called from an event handler, which would
|
||||
# cancel itself during itself and never actually complete the
|
||||
|
|
Loading…
Reference in New Issue
Block a user