Handle dispatcher CancelledError during disconnect

This commit is contained in:
Lonami Exo 2023-10-18 20:38:45 +02:00
parent c49f0827b1
commit 854d3745b3
2 changed files with 3 additions and 1 deletions

View File

@ -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"

View File

@ -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.