Skip to content

Commit 0a504c2

Browse files
committed
doc
1 parent 00b6476 commit 0a504c2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,22 @@ async def maybe_await(
6868

6969

7070
async def cancel_and_wait(task: asyncio.Task) -> None:
71-
"""Cancels the given task and waits for it to finish.
71+
"""Cancels the given task and waits for it to complete.
7272
73-
Accounts for the case where the tasks's owner function is being cancelled
73+
Accounts for the case where the tasks's owner function is being cancelled.
74+
In that case, it propagates the cancellation exception upstream.
7475
"""
7576
task.cancel()
7677
try:
7778
# NOTE shield ensures that cancellation of the caller function won’t stop you
7879
# from observing the cancellation/finalization of task.
7980
await asyncio.shield(task)
81+
8082
except asyncio.CancelledError:
8183
if not task.cancelled():
8284
# task owner function is being cancelled -> propagate cancellation
8385
raise
86+
8487
# else: task cancellation is complete, we can safely ignore it
8588
_logger.debug(
8689
"Task %s cancellation is complete",

0 commit comments

Comments
 (0)