Skip to content

Commit 8e7d867

Browse files
committed
fix cancelling
1 parent dceab47 commit 8e7d867

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/common-library/src/common_library/async_tools.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ async def cancel_wait_task(
9292

9393
cancelling = task.cancel()
9494
if not cancelling:
95-
return # task was alredy cancelled
95+
return # task could not be cancelled (either already done or something else)
9696

9797
assert task.cancelling() # nosec
9898
assert not task.cancelled() # nosec
99+
assert not task.done() # nosec
99100

100101
try:
101102

@@ -106,8 +107,9 @@ async def cancel_wait_task(
106107
)
107108

108109
except asyncio.CancelledError:
109-
if not task.cancelled():
110-
# task owner function is being cancelled -> propagate cancellation
110+
assert task.done() # nosec
111+
if asyncio.current_task().cancelling() > 0:
112+
# owner function is being cancelled -> propagate cancellation
111113
raise
112114

113115
# else: task cancellation is complete, we can safely ignore it

0 commit comments

Comments
 (0)