Skip to content

Commit b36f01d

Browse files
authored
gh-141186: document asyncio.Task cancellation propagation behavior (#141249)
1 parent 0ac890b commit b36f01d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Doc/library/asyncio-task.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ Task Object
12211221

12221222
To cancel a running Task use the :meth:`cancel` method. Calling it
12231223
will cause the Task to throw a :exc:`CancelledError` exception into
1224-
the wrapped coroutine. If a coroutine is awaiting on a Future
1225-
object during cancellation, the Future object will be cancelled.
1224+
the wrapped coroutine. If a coroutine is awaiting on a future-like
1225+
object during cancellation, the awaited object will be cancelled.
12261226

12271227
:meth:`cancelled` can be used to check if the Task was cancelled.
12281228
The method returns ``True`` if the wrapped coroutine did not
@@ -1411,6 +1411,10 @@ Task Object
14111411
the cancellation, it needs to call :meth:`Task.uncancel` in addition
14121412
to catching the exception.
14131413

1414+
If the Task being cancelled is currently awaiting on a future-like
1415+
object, that awaited object will also be cancelled. This cancellation
1416+
propagates down the entire chain of awaited objects.
1417+
14141418
.. versionchanged:: 3.9
14151419
Added the *msg* parameter.
14161420

0 commit comments

Comments
 (0)