Fixing log_out problems on mac os devices

This commit is contained in:
Tural Gurbanov 2017-08-18 14:22:27 +01:00
parent afcddfd7c1
commit 763372390f

View File

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