@@ -256,8 +256,9 @@ Creating Tasks
256
256
257
257
.. note ::
258
258
259
- :meth: `asyncio.TaskGroup.create_task ` is a newer alternative
260
- that allows for convenient waiting for a group of related tasks.
259
+ :meth: `asyncio.TaskGroup.create_task ` is a new alternative
260
+ leveraging structural concurrency; it allows for waiting
261
+ for a group of related tasks with strong safety guarantees.
261
262
262
263
.. important ::
263
264
@@ -340,7 +341,7 @@ Example::
340
341
async with asyncio.TaskGroup() as tg:
341
342
task1 = tg.create_task(some_coro(...))
342
343
task2 = tg.create_task(another_coro(...))
343
- print("Both tasks have completed now. ")
344
+ print(f "Both tasks have completed now: {task1.result()}, {task2.result()} ")
344
345
345
346
The ``async with `` statement will wait for all tasks in the group to finish.
346
347
While waiting, new tasks may still be added to the group
@@ -459,8 +460,12 @@ Running Tasks Concurrently
459
460
Tasks/Futures to be cancelled.
460
461
461
462
.. note ::
462
- A more modern way to create and run tasks concurrently and
463
- wait for their completion is :class: `asyncio.TaskGroup `.
463
+ A new alternative to create and run tasks concurrently and
464
+ wait for their completion is :class: `asyncio.TaskGroup `. *TaskGroup *
465
+ provides stronger safety guarantees than *gather * for scheduling a nesting of subtasks:
466
+ if a task (or a subtask, a task scheduled by a task)
467
+ raises an exception, *TaskGroup * will, while *gather * will not,
468
+ cancel the remaining scheduled tasks).
464
469
465
470
.. _asyncio_example_gather :
466
471
0 commit comments