From a6ce88e2bb9e2c241848f882a2dc2e39e539415e Mon Sep 17 00:00:00 2001 From: Tor Arvid Lund Date: Mon, 20 Feb 2023 12:51:11 +0100 Subject: [PATCH] Prevent 'Task exception was never retrieved' If future.exception() is not called (even on cancelled futures), it seems Python will then log 'Task exception was never retrieved'. Rewriting this logic slightly should hopefully achieve the same functionality while preventing the Python errors. --- aio_pika/tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aio_pika/tools.py b/aio_pika/tools.py index b7639f2c..9ff77c37 100644 --- a/aio_pika/tools.py +++ b/aio_pika/tools.py @@ -38,10 +38,12 @@ def iscoroutinepartial(fn: Callable[..., Any]) -> bool: def _task_done(future: asyncio.Future) -> None: - if not future.cancelled(): + try: exc = future.exception() if exc is not None: raise exc + except asyncio.CancelledError: + pass def create_task(