mirror of
https://github.com/python/cpython.git
synced 2026-05-04 09:31:02 +00:00
gh-108951: document addition of TaskGroup.cancel() (#149031)
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
993e204ad4
commit
8a8d737be2
3 changed files with 15 additions and 3 deletions
|
|
@ -394,8 +394,8 @@ Example::
|
|||
The ``async with`` statement will wait for all tasks in the group to finish.
|
||||
While waiting, new tasks may still be added to the group
|
||||
(for example, by passing ``tg`` into one of the coroutines
|
||||
and calling ``tg.create_task()`` in that coroutine). There is also opportunity
|
||||
to short-circuit the entire task group with ``tg.cancel()``, based on some condition.
|
||||
and calling ``tg.create_task()`` in that coroutine). There is also opportunity to
|
||||
request termination of the entire task group with ``tg.cancel()``, based on some condition.
|
||||
Once the last task has finished and the ``async with`` block is exited,
|
||||
no new tasks may be added to the group.
|
||||
|
||||
|
|
|
|||
|
|
@ -741,6 +741,17 @@ ast
|
|||
(Contributed by Stan Ulbrych in :gh:`148981`.)
|
||||
|
||||
|
||||
asyncio
|
||||
-------
|
||||
|
||||
* Added :meth:`TaskGroup.cancel <asyncio.TaskGroup.cancel>` to allow early
|
||||
termination of a task group, for instance, when the goal of the tasks has
|
||||
been achieved or their services are no longer needed.
|
||||
Previously this would involve unintuitive boilerplate such as an extra task
|
||||
raising a custom exception which is then suppressed as it exits the task group.
|
||||
(Contributed by John Belmonte in :gh:`127214`.)
|
||||
|
||||
|
||||
base64
|
||||
------
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
Add :meth:`~asyncio.TaskGroup.cancel` which cancels unfinished tasks and exits the group without error.
|
||||
:mod:`asyncio`: Add :meth:`TaskGroup.cancel <asyncio.TaskGroup.cancel>` which cancels
|
||||
unfinished tasks and exits the group without raising :exc:`asyncio.CancelledError`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue