Skip to content

Commit

Permalink
Fix bug: CancelledError on client.close() (#1)
Browse files Browse the repository at this point in the history
* not in PY-3.10

* CancelledError

Co-authored-by: Andrei Pozolotin <[email protected]>
  • Loading branch information
khanhldt and Andrei-Pozolotin authored Oct 15, 2022
1 parent 6c69ba5 commit 6cbfef7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aiocometd/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
2 changes: 1 addition & 1 deletion aiocometd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion aiocometd/transports/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion aiocometd/transports/websocket.py
Original file line number Diff line number Diff line change
@@ -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, \
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6cbfef7

Please sign in to comment.