Fixing log_out problems on mac os devices

This commit is contained in:
Tural Gurbanov 2017-08-18 14:22:27 +01:00
parent 59f47fe9d9
commit 20a10dfdc3

View File

@ -316,33 +316,27 @@ class TelegramClient(TelegramBareClient):
def log_out(self):
"""Logs out and deletes the current session.
Returns True if everything went okay."""
# Special flag when logging out (so the ack request confirms it)
self._sender.logging_out = True
try:
self(LogOutRequest())
self.disconnect()
if not self.session.delete():
return False
self.session = None
return True
except OSError as e:
# macos issue: https://github.com/veusz/veusz/issues/54
# socket has been already closed
if e.errno == errno.ENOTCONN:
if not self.session.delete():
return False
self.session = None
return True
else:
# socket has been already closed (Errno 57)
# if any other - fail
if e.errno != errno.ENOTCONN:
raise e
except (RPCError, ConnectionError):
# Something happened when logging out, restore the state back
self._sender.logging_out = False
return False
self.session.delete()
self.session = None
return True
def get_me(self):
"""Gets "me" (the self user) which is currently authenticated,
or None if the request fails (hence, not authenticated)."""