From 15445777575daf35ae2208e2763d7c7f7c209f52 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 4 Jan 2019 11:26:57 +0100 Subject: [PATCH] Don't raise inside __del__ (#1073) --- telethon/client/telegrambaseclient.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index d048c492..52d860b3 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -375,7 +375,13 @@ class TelegramBaseClient(abc.ABC): # able to close the pending tasks properly, and letting the script # complete without calling disconnect causes the script to trigger # 100% CPU load. Call disconnect to make sure it doesn't happen. - self.disconnect() + try: + self.disconnect() + except Exception: + # Arguably not the best solution, but worth trying if the user + # forgot to disconnect; normally this is fine but sometimes it + # can fail (https://github.com/LonamiWebs/Telethon/issues/1073) + pass async def _switch_dc(self, new_dc): """