Skip to content

Commit 7e25c26

Browse files
committed
document some ways to use cancel()
1 parent dac2cef commit 7e25c26

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/asyncio-task.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ and reliable way to wait for all tasks in the group to finish.
359359
:meth:`cancel` is idempotent and may be called after the task group has
360360
already exited.
361361

362+
Ways to use :meth:`cancel`:
363+
* call it from the task group body based on some condition or
364+
event
365+
* pass the task group instance to child tasks via :meth:`create_task`,
366+
allowing a child task to conditionally cancel the entire entire group
367+
* pass the task group instance or bound :meth:`cancel` method to some
368+
other task *before* opening the task group, allowing remote cancellation
369+
362370
.. versionadded:: next
363371

364372
Example::

0 commit comments

Comments
 (0)