There was an error while loading. Please reload this page.
1 parent d768d94 commit 55e9f46Copy full SHA for 55e9f46
1 file changed
Doc/library/asyncio-task.rst
@@ -288,6 +288,17 @@ Creating tasks
288
# completion:
289
task.add_done_callback(background_tasks.discard)
290
291
+ Note that this approach never awaits the tasks, so if a task
292
+ fails, its exception is never retrieved and asyncio logs a
293
+ "Task exception was never retrieved" message when the task is
294
+ garbage collected. To avoid this, use :class:`asyncio.TaskGroup`
295
+ which keeps a strong reference to each task, awaits them and
296
+ propagates their exceptions::
297
+
298
+ async with asyncio.TaskGroup() as tg:
299
+ for i in range(10):
300
+ tg.create_task(some_coro(param=i))
301
302
.. versionadded:: 3.7
303
304
.. versionchanged:: 3.8
0 commit comments