[Python-checkins] gh-102560 Add docstrings to asyncio.TaskGroup (GH-102565)

miss-islington webhook-mailer at python.org
Wed Mar 15 03:27:41 EDT 2023


https://github.com/python/cpython/commit/7e5ba351e0702bdff50ff5755082ef2cc5ace381
commit: 7e5ba351e0702bdff50ff5755082ef2cc5ace381
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2023-03-15T00:27:33-07:00
summary:

gh-102560 Add docstrings to asyncio.TaskGroup (GH-102565)

(cherry picked from commit e94edab727d07bef851e0e1a345e18a453be863d)

Co-authored-by: JosephSBoyle <48555120+JosephSBoyle at users.noreply.github.com>

files:
M Lib/asyncio/taskgroups.py

diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py
index 911419e1769c..0fdea3697ece 100644
--- a/Lib/asyncio/taskgroups.py
+++ b/Lib/asyncio/taskgroups.py
@@ -10,7 +10,21 @@
 
 
 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 @@ async def __aexit__(self, et, exc, tb):
                 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:



More information about the Python-checkins mailing list