From 6cbfef719f9771f3797d13868dba8f961f0a199b Mon Sep 17 00:00:00 2001 From: Khanh Le Do <5936195+khanhldt@users.noreply.github.com> Date: Sat, 15 Oct 2022 11:59:54 -0700 Subject: [PATCH] Fix bug: CancelledError on client.close() (#1) * not in PY-3.10 * CancelledError Co-authored-by: Andrei Pozolotin --- aiocometd/_metadata.py | 2 +- aiocometd/client.py | 2 +- aiocometd/transports/base.py | 4 +++- aiocometd/transports/websocket.py | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/aiocometd/_metadata.py b/aiocometd/_metadata.py index 9a253ff..e20003c 100644 --- a/aiocometd/_metadata.py +++ b/aiocometd/_metadata.py @@ -8,6 +8,6 @@ "Coverage": "https://coveralls.io/github/robertmrk/aiocometd", "Docs": "http://aiocometd.readthedocs.io/" } -VERSION = "0.4.5" +VERSION = "0.4.5.3" AUTHOR = "Róbert Márki" AUTHOR_EMAIL = "gsmiko@gmail.com" diff --git a/aiocometd/client.py b/aiocometd/client.py index cb84578..c711acb 100644 --- a/aiocometd/client.py +++ b/aiocometd/client.py @@ -510,7 +510,7 @@ async def _get_message(self, connection_timeout: Union[int, float]) \ done, pending = await asyncio.wait( tasks, return_when=asyncio.FIRST_COMPLETED, - loop=self._loop) + ) # not in PY-3.10 loop=self._loop) # cancel all pending tasks for task in pending: diff --git a/aiocometd/transports/base.py b/aiocometd/transports/base.py index be6114f..0d260f4 100644 --- a/aiocometd/transports/base.py +++ b/aiocometd/transports/base.py @@ -1,5 +1,7 @@ """Base transtport abstract class definition""" import asyncio +from asyncio.exceptions import CancelledError + import logging from abc import abstractmethod from contextlib import suppress @@ -510,7 +512,7 @@ def _connect_done(self, future: "asyncio.Future[JsonObject]") -> None: "reconnect" in result["advice"]): reconnect_advice = result["advice"]["reconnect"] self._state = TransportState.CONNECTED - except Exception as error: # pylint: disable=broad-except + except (Exception, CancelledError) as error: # pylint: disable=broad-except # issue #7 result = error reconnect_timeout = self._reconnect_timeout if self.state != TransportState.DISCONNECTING: diff --git a/aiocometd/transports/websocket.py b/aiocometd/transports/websocket.py index 8334a1d..b793cbd 100644 --- a/aiocometd/transports/websocket.py +++ b/aiocometd/transports/websocket.py @@ -1,5 +1,7 @@ """Websocket transport class definition""" import asyncio +from asyncio.exceptions import CancelledError + import logging from contextlib import suppress from typing import Callable, Optional, AsyncContextManager, Any, Awaitable, \ @@ -257,7 +259,7 @@ def _receive_done(self, future: "asyncio.Task[None]") -> None: # extract the result of the future try: result = future.result() - except Exception as error: # pylint: disable=broad-except + except (Exception, CancelledError) as error: # pylint: disable=broad-except # issue #7 result = error # clear the receive task self._receive_task = None