Skip to content

Commit bd2b425

Browse files
committed
cancel_and_wait: Re-raise if it was our task
Reraise the cancel error if it was our task that was cancelled. Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent e1de106 commit bd2b425

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/frequenz/sdk/_internal/_asyncio.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ async def cancel_and_await(task: asyncio.Task[Any]) -> None:
2323
2424
Args:
2525
task: The task to be cancelled and waited for.
26+
27+
Raises:
28+
asyncio.CancelledError: when our task was cancelled
2629
"""
2730
if task.done():
2831
return
2932
task.cancel()
3033
try:
3134
await task
3235
except asyncio.CancelledError:
33-
pass
36+
if not task.cancelled():
37+
raise
3438

3539

3640
def is_loop_running() -> bool:

0 commit comments

Comments
 (0)