gh-138199: Address potential confusion regarding threading in the asyncio HOWTO (GH-138200)

This commit is contained in:
Alexander Nordin 2025-11-24 06:08:49 -08:00 committed by GitHub
parent 0afcb51d17
commit a4f4225213
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -175,9 +175,12 @@ Creating a task automatically schedules it for execution (by adding a
callback to run it in the event loop's to-do list, that is, collection of jobs). callback to run it in the event loop's to-do list, that is, collection of jobs).
The recommended way to create tasks is via :func:`asyncio.create_task`. The recommended way to create tasks is via :func:`asyncio.create_task`.
Since there's only one event loop (in each thread), :mod:`!asyncio` takes :mod:`!asyncio` automatically associates tasks with the event loop for you.
care of associating the task with the event loop for you. This automatic association was purposely designed into :mod:`!asyncio` for
As such, there's no need to specify the event loop. the sake of simplicity.
Without it, you'd have to keep track of the event loop object and pass it to
any coroutine function that wants to create tasks, adding redundant clutter
to your code.
:: ::