From 368c3940d32f69f2a982cc2e3869ab03a3471145 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 21 Mar 2019 13:33:39 +0000 Subject: [PATCH] check if the fut was canncelled before setting result or exception we mostly expect the fut to be cancelled if shutdown is happening, so this is very likely --- aiorun.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aiorun.py b/aiorun.py index 0aa8d75..6e3b7df 100644 --- a/aiorun.py +++ b/aiorun.py @@ -63,12 +63,12 @@ async def coro_proxy(): """ try: result = await coro - try: - fut.set_result(result) - except asyncio.InvalidStateError: - logger.warning('Failed to set result.') except (CancelledError, Exception) as e: - fut.set_exception(e) + if not fut.cancelled(): + fut.set_exception(e) + else: + if not fut.cancelled(): + fut.set_result(result) new_coro = coro_proxy() # We'll taskify this one instead of coro. _DO_NOT_CANCEL_COROS.add(new_coro) # The new task must not be cancelled.