[3.13] gh-104091: Suggest TaskGroup for running background tasks in asyncio.create_task() docs (GH-155133) (#155149)

Yhg1s <[email protected]> Tue, 04 Aug 2026 05:16:58 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/a2ceffd35016e667f27f04ac80548fe02b649f93
commit: a2ceffd35016e667f27f04ac80548fe02b649f93
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: Yhg1s <[email protected]>
date: 2026-08-04T11:16:16+02:00
summary:

[3.13] gh-104091: Suggest TaskGroup for running background tasks in asyncio.create_task() docs (GH-155133) (#155149)

gh-104091: Suggest TaskGroup for running background tasks in asyncio.create_task() docs (GH-155133)
(cherry picked from commit 36250a9b45cd898aa51c438cfb61fa1408266ffc)

Co-authored-by: Kumar Aditya <[email protected]>

files:
M Doc/library/asyncio-task.rst

diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index 16f04e6c745a15..cd719b302a74ec 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -282,6 +282,17 @@ Creating tasks
               # completion:
               task.add_done_callback(background_tasks.discard)
 
+      Note that this approach never awaits the tasks, so if a task
+      fails, its exception is never retrieved and asyncio logs a
+      "Task exception was never retrieved" message when the task is
+      garbage collected.  To avoid this, use :class:`asyncio.TaskGroup`
+      which keeps a strong reference to each task, awaits them and
+      propagates their exceptions::
+
+          async with asyncio.TaskGroup() as tg:
+              for i in range(10):
+                  tg.create_task(some_coro(param=i))
+
    .. versionadded:: 3.7
 
    .. versionchanged:: 3.8

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]