Skip to content

Commit 0527218

Browse files
committed
remove all references to queue besides the initial analogy.
1 parent 27c026b commit 0527218

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

Doc/howto/a-conceptual-overview-of-asyncio.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ If there are no more jobs pending execution, the event loop is smart enough to
6262
rest and avoid needlessly wasting CPU cycles, and will come back when there's
6363
more work to be done.
6464

65-
Effective execution relies on tasks sharing well and cooperating; a greedy job
65+
Effective execution relies on jobs sharing well and cooperating; a greedy job
6666
could hog control and leave the other jobs to starve, rendering the overall
6767
event loop approach rather useless.
6868

@@ -71,7 +71,7 @@ event loop approach rather useless.
7171
import asyncio
7272

7373
# This creates an event loop and indefinitely cycles through
74-
# its queue of tasks.
74+
# its collection of jobs.
7575
event_loop = asyncio.new_event_loop()
7676
event_loop.run_forever()
7777

@@ -172,7 +172,8 @@ functions) tied to an event loop.
172172
A task also maintains a list of callback functions whose importance will become
173173
clear in a moment when we discuss :keyword:`await`.
174174
The recommended way to create tasks is via :func:`asyncio.create_task`.
175-
Creating a task automatically adds it to the event loop's queue of tasks.
175+
Creating a task automatically schedules it for execution (by adding it to the
176+
event loop's to-do list, that is, collection of jobs).
176177

177178
Since there's only one event loop (in each thread), :mod:`!asyncio` takes care of
178179
associating the task with the event loop for you. As such, there's no need
@@ -181,7 +182,7 @@ to specify the event loop.
181182
::
182183

183184
coroutine = loudmouth_penguin(magic_number=5)
184-
# This creates a Task object and puts it on the event loop's queue.
185+
# This creates a Task object and schedules its execution via the event loop.
185186
task = asyncio.create_task(coroutine)
186187

187188
Earlier, we manually created the event loop and set it to run forever.
@@ -240,7 +241,7 @@ in this case, a call to resume ``plant_a_tree()``.
240241

241242
Generally speaking, when the awaited task finishes (``dig_the_hole_task``),
242243
the original task or coroutine (``plant_a_tree()``) is added back to the event
243-
loops queue to be resumed.
244+
loops to-do list to be resumed.
244245

245246
This is a basic, yet reliable mental model.
246247
In practice, the control handoffs are slightly more complex, but not by much.
@@ -271,8 +272,8 @@ Consider this program::
271272

272273
asyncio.run(main())
273274

274-
The first statement in the coroutine ``main()`` creates ``task_b`` and places
275-
it on the event loop's queue.
275+
The first statement in the coroutine ``main()`` creates ``task_b`` and schedules
276+
it for execution via the event loop.
276277
Then, ``coro_a()`` is repeatedly awaited. Control never cedes to the
277278
event loop which is why we see the output of all three ``coro_a()``
278279
invocations before ``coro_b()``'s output:
@@ -287,8 +288,8 @@ invocations before ``coro_b()``'s output:
287288
If we change ``await coro_a()`` to ``await asyncio.create_task(coro_a())``, the
288289
behavior changes.
289290
The coroutine ``main()`` cedes control to the event loop with that statement.
290-
The event loop then works through its queue, calling ``coro_b()`` and then
291-
``coro_a()`` before resuming the coroutine ``main()``.
291+
The event loop then proceeds through its backlog of work, calling ``coro_b()``
292+
and then ``coro_a()`` before resuming the coroutine ``main()``.
292293

293294
.. code-block:: none
294295
@@ -452,7 +453,7 @@ We'll go through an example of how you could leverage a future to create your
452453
own variant of asynchronous sleep (``async_sleep``) which mimics
453454
:func:`asyncio.sleep`.
454455

455-
This snippet puts a few tasks on the event loop's queue and then awaits a
456+
This snippet registers a few tasks with the event loop and then awaits a
456457
coroutine wrapped in a task: ``async_sleep(3)``.
457458
We want that task to finish only after three seconds have elapsed, but without
458459
preventing other tasks from running.
@@ -508,16 +509,16 @@ This is effectively the same as calling ``asyncio.sleep(0)``, but this approach
508509
offers more clarity, not to mention it's somewhat cheating to use
509510
``asyncio.sleep`` when showcasing how to implement it!
510511

511-
As usual, the event loop cycles through its queue of tasks, giving them control
512+
As usual, the event loop cycles through its tasks, giving them control
512513
and receiving control back when they pause or finish.
513514
The ``watcher_task``, which runs the coroutine ``_sleep_watcher(...)``, will
514-
be invoked once per full cycle of the event loop's queue.
515+
be invoked once per full cycle of the event loop.
515516
On each resumption, it'll check the time and if not enough has elapsed, then
516517
it'll pause once again and hand control back to the event loop.
517518
Eventually, enough time will have elapsed, and ``_sleep_watcher(...)`` will
518519
mark the future as done, and then itself finish too by breaking out of the
519520
infinite ``while`` loop.
520-
Given this helper task is only invoked once per cycle of the event loop's queue,
521+
Given this helper task is only invoked once per cycle of the event loop,
521522
you'd be correct to note that this asynchronous sleep will sleep *at least*
522523
three seconds, rather than exactly three seconds.
523524
Note this is also of true of ``asyncio.sleep``.

0 commit comments

Comments
 (0)