Skip to content

Commit

Permalink
Handle dispatcher CancelledError during disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Oct 18, 2023
1 parent c49f082 commit 854d374
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/src/telethon/_impl/client/client/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion client/src/telethon/_impl/client/client/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 854d374

Please sign in to comment.