@@ -357,12 +357,13 @@ and reliable way to wait for all tasks in the group to finish.
357357
358358 .. method :: cancel()
359359
360- Cancel the task group.
360+ Cancel the task group. This is a non-exceptional, early exit of the
361+ task group's lifetime -- useful once the group's goal has been met or
362+ its services no longer needed.
361363
362364 :meth: `~asyncio.Task.cancel ` will be called on any tasks in the group that
363- aren't yet done, as well as the parent (body) of the group. This will
364- cause the task group context manager to exit *without *
365- :exc: `asyncio.CancelledError ` being raised.
365+ aren't yet done, as well as the parent (body) of the group. The task group
366+ context manager will exit *without * :exc: `asyncio.CancelledError ` being raised.
366367
367368 If :meth: `cancel ` is called before entering the task group, the group will be
368369 cancelled upon entry. This is useful for patterns where one piece of
@@ -372,7 +373,7 @@ and reliable way to wait for all tasks in the group to finish.
372373 :meth: `cancel ` is idempotent and may be called after the task group has
373374 already exited.
374375
375- Ways to use :meth: `cancel `:
376+ Some ways to use :meth: `cancel `:
376377
377378 * call it from the task group body based on some condition or event
378379 * pass the task group instance to child tasks via :meth: `create_task `, allowing a child
@@ -393,7 +394,8 @@ Example::
393394The ``async with `` statement will wait for all tasks in the group to finish.
394395While waiting, new tasks may still be added to the group
395396(for example, by passing ``tg `` into one of the coroutines
396- and calling ``tg.create_task() `` in that coroutine).
397+ and calling ``tg.create_task() `` in that coroutine). There is also opportunity
398+ to short-circuit the entire task group with :meth: `cancel `, based on some condition.
397399Once the last task has finished and the ``async with `` block is exited,
398400no new tasks may be added to the group.
399401
0 commit comments