From 05a8723d362e1dc23414e581ea2d1d2a6df2d175 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 17 Sep 2017 16:37:08 +0200 Subject: [PATCH] Catch calling .receive() when .sender is None on recv_thread --- telethon/telegram_client.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 559bdba1..dc5b8626 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -1004,6 +1004,13 @@ class TelegramClient(TelegramBareClient): self._last_ping = datetime.now() self._sender.receive(update_state=self.updates) + except AttributeError: + # 'NoneType' object has no attribute 'receive'. + # The only moment when this can happen is reconnection + # was triggered from another thread and the ._sender + # was set to None, so close this thread and exit by return. + self._recv_thread = None + return except TimeoutError: # No problem. pass