Work around Python 3.5.2 bug causing 100% CPU load on script's end

This commit is contained in:
Lonami Exo 2018-06-26 10:54:26 +02:00
parent f295ea668a
commit a43c6c2b68

View File

@ -297,6 +297,16 @@ class TelegramBaseClient(abc.ABC):
self.session.close()
def __del__(self):
# Python 3.5.2's ``asyncio`` mod seems to have a bug where it's not
# 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.
if self._loop.is_running():
self._loop.create_task(self.disconnect())
else:
self._loop.run_until_complete(self.disconnect())
async def _switch_dc(self, new_dc):
"""
Permanently switches the current connection to the new data center.