Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e94edab

Browse files
authored
gh-102560 Add docstrings to asyncio.TaskGroup (#102565)
1 parent 5fce813 commit e94edab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/asyncio/taskgroups.py

+18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010

1111

1212
class TaskGroup:
13+
"""Asynchronous context manager for managing groups of tasks.
1314
15+
Example use:
16+
17+
async with asyncio.TaskGroup() as group:
18+
task1 = group.create_task(some_coroutine(...))
19+
task2 = group.create_task(other_coroutine(...))
20+
print("Both tasks have completed now.")
21+
22+
All tasks are awaited when the context manager exits.
23+
24+
Any exceptions other than `asyncio.CancelledError` raised within
25+
a task will cancel all remaining tasks and wait for them to exit.
26+
The exceptions are then combined and raised as an `ExceptionGroup`.
27+
"""
1428
def __init__(self):
1529
self._entered = False
1630
self._exiting = False
@@ -135,6 +149,10 @@ async def __aexit__(self, et, exc, tb):
135149
self._errors = None
136150

137151
def create_task(self, coro, *, name=None, context=None):
152+
"""Create a new task in this group and return it.
153+
154+
Similar to `asyncio.create_task`.
155+
"""
138156
if not self._entered:
139157
raise RuntimeError(f"TaskGroup {self!r} has not been entered")
140158
if self._exiting and not self._tasks:

0 commit comments

Comments
 (0)