summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorJosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com>2023-03-15 00:33:19 (GMT)
committerGitHub <noreply@github.com>2023-03-15 00:33:19 (GMT)
commite94edab727d07bef851e0e1a345e18a453be863d (patch)
tree0721c0464707881f18991c4967e4005e4d8f89d5 /Lib/asyncio
parent5fce813d8e547d6508daa386b67f230105c3a174 (diff)
downloadcpython-e94edab727d07bef851e0e1a345e18a453be863d.zip
cpython-e94edab727d07bef851e0e1a345e18a453be863d.tar.gz
cpython-e94edab727d07bef851e0e1a345e18a453be863d.tar.bz2
gh-102560 Add docstrings to asyncio.TaskGroup (#102565)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/taskgroups.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 911419e..0fdea36 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -10,7 +10,21 @@ from . import tasks
class TaskGroup:
+ """Asynchronous context manager for managing groups of tasks.
+ Example use:
+
+ async with asyncio.TaskGroup() as group:
+ task1 = group.create_task(some_coroutine(...))
+ task2 = group.create_task(other_coroutine(...))
+ print("Both tasks have completed now.")
+
+ All tasks are awaited when the context manager exits.
+
+ Any exceptions other than `asyncio.CancelledError` raised within
+ a task will cancel all remaining tasks and wait for them to exit.
+ The exceptions are then combined and raised as an `ExceptionGroup`.
+ """
def __init__(self):
self._entered = False
self._exiting = False
@@ -135,6 +149,10 @@ class TaskGroup:
self._errors = None
def create_task(self, coro, *, name=None, context=None):
+ """Create a new task in this group and return it.
+
+ Similar to `asyncio.create_task`.
+ """
if not self._entered:
raise RuntimeError(f"TaskGroup {self!r} has not been entered")
if self._exiting and not self._tasks: