From 854d3745b3c949c68cd98fb2a78c190d6664e8ea Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 18 Oct 2023 20:38:45 +0200 Subject: [PATCH] Handle dispatcher CancelledError during disconnect --- client/src/telethon/_impl/client/client/net.py | 2 ++ client/src/telethon/_impl/client/client/updates.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/telethon/_impl/client/client/net.py b/client/src/telethon/_impl/client/client/net.py index 93e81999..b094960f 100644 --- a/client/src/telethon/_impl/client/client/net.py +++ b/client/src/telethon/_impl/client/client/net.py @@ -210,6 +210,8 @@ async def disconnect(self: Client) -> None: self._dispatcher.cancel() try: await self._dispatcher + except asyncio.CancelledError: + pass except Exception: self._logger.exception( "unhandled exception when cancelling dispatcher; this is a bug" diff --git a/client/src/telethon/_impl/client/client/updates.py b/client/src/telethon/_impl/client/client/updates.py index bd3f6440..e65dfdb1 100644 --- a/client/src/telethon/_impl/client/client/updates.py +++ b/client/src/telethon/_impl/client/client/updates.py @@ -130,7 +130,7 @@ async def dispatcher(client: Client) -> None: try: await dispatch_next(client) except asyncio.CancelledError: - return + raise except Exception as e: if isinstance(e, RuntimeError) and loop.is_closed(): # User probably forgot to call disconnect.