From 1bd02d64c50b3209a954c9836a66e4d7e0088266 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 27 Dec 2019 10:46:01 +0100 Subject: [PATCH] Handle RuntimeError on helpers._cancel and improve logging --- telethon/helpers.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/telethon/helpers.py b/telethon/helpers.py index 190da04a..4c8d4799 100644 --- a/telethon/helpers.py +++ b/telethon/helpers.py @@ -106,8 +106,20 @@ async def _cancel(log, **tasks): await task except asyncio.CancelledError: pass + except RuntimeError: + # Probably: RuntimeError: await wasn't used with future + # + # Happens with _asyncio.Task instances (in "Task cancelling" state) + # trying to SIGINT the program right during initial connection, on + # _recv_loop coroutine (but we're creating its task explicitly with + # a loop, so how can it bug out like this?). + # + # Since we're aware of this error there's no point in logging it. + # *May* be https://bugs.python.org/issue37172 + pass except Exception: - log.exception('Unhandled exception from %s after cancel', name) + log.exception('Unhandled exception from %s after cancelling ' + '%s (%s)', name, type(task), task) def _sync_enter(self):