Skip to content

Commit

Permalink
[FIX] Do not call task.cancel() when the coroutine itself is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia committed Nov 4, 2023
1 parent 381074f commit 6fffec7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/easynetwork/lowlevel/asyncio/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,20 @@ async def coroutine() -> None:
def on_fut_done(future: concurrent.futures.Future[_T]) -> None:
if future.cancelled():
if self.__is_in_this_loop_thread(loop):
task.cancel()
if not cancelling:
task.cancel()
return
with contextlib.suppress(RuntimeError):
self.run_sync(task.cancel)

task = TaskUtils.current_asyncio_task()
loop = task.get_loop()
cancelling: bool = False
try:
future.add_done_callback(on_fut_done)
result = await coro_func(*args, **kwargs)
except asyncio.CancelledError:
cancelling = True
future.cancel()
future.set_running_or_notify_cancel()
raise
Expand Down

0 comments on commit 6fffec7

Please sign in to comment.