File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
packages/common-library/src/common_library Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -68,19 +68,22 @@ async def maybe_await(
6868
6969
7070async 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" ,
You can’t perform that action at this time.
0 commit comments