mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Fix log_out problems on macOS devices
This commit is contained in:
		
							parent
							
								
									ffb1cf483d
								
							
						
					
					
						commit
						12b84c929a
					
				| 
						 | 
					@ -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
 | 
					            # Fail on any other error
 | 
				
			||||||
            return True
 | 
					            if e.errno != errno.ENOTCONN:
 | 
				
			||||||
 | 
					                raise
 | 
				
			||||||
        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)."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user