Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/c-api/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,4 @@ Importing Modules

On error, return NULL with an exception set.

.. versionadded:: next
.. versionadded:: 3.15
4 changes: 2 additions & 2 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

See :c:func:`PyUnstable_ThreadState_ResetStackProtection` for undoing this operation.

.. versionadded:: next
.. versionadded:: 3.15


.. c:function:: void PyUnstable_ThreadState_ResetStackProtection(PyThreadState *tstate)
Expand All @@ -1400,7 +1400,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.

See :c:func:`PyUnstable_ThreadState_SetStackProtection` for an explanation.

.. versionadded:: next
.. versionadded:: 3.15


.. c:function:: PyInterpreterState* PyInterpreterState_Get(void)
Expand Down
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 25 additions & 14 deletions Doc/howto/a-conceptual-overview-of-asyncio.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _a-conceptual-overview-of-asyncio:

****************************************
A Conceptual Overview of :mod:`!asyncio`
A conceptual overview of :mod:`!asyncio`
****************************************

This :ref:`HOWTO <how-tos>` article seeks to help you build a sturdy mental
Expand Down Expand Up @@ -37,15 +37,15 @@ In part 1, we'll cover the main, high-level building blocks of :mod:`!asyncio`:
the event loop, coroutine functions, coroutine objects, tasks, and ``await``.

==========
Event Loop
Event loop
==========

Everything in :mod:`!asyncio` happens relative to the event loop.
It's the star of the show.
It's the star of the show, but prefers to work behind the scenes, managing
and coordinating resources.
It's like an orchestra conductor.
It's behind the scenes managing resources.
Some power is explicitly granted to it, but a lot of its ability to get things
done comes from the respect and cooperation of its worker bees.
done comes from the respect and cooperation of its band members.

In more technical terms, the event loop contains a collection of jobs to be run.
Some jobs are added directly by you, and some indirectly by :mod:`!asyncio`.
Expand All @@ -59,7 +59,7 @@ This process repeats indefinitely, with the event loop cycling endlessly
onwards.
If there are no more jobs pending execution, the event loop is smart enough to
rest and avoid needlessly wasting CPU cycles, and will come back when there's
more work to be done.
more work to be done, such as when I/O operations complete or timers expire.

Effective execution relies on jobs sharing well and cooperating; a greedy job
could hog control and leave the other jobs to starve, rendering the overall
Expand Down Expand Up @@ -170,14 +170,14 @@ Roughly speaking, :ref:`tasks <asyncio-task-obj>` are coroutines (not coroutine
functions) tied to an event loop.
A task also maintains a list of callback functions whose importance will become
clear in a moment when we discuss :keyword:`await`.
The recommended way to create tasks is via :func:`asyncio.create_task`.

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).
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 care of
associating the task with the event loop for you. As such, there's no need
to specify the event loop.
Since there's only one event loop (in each thread), :mod:`!asyncio` takes
care of associating the task with the event loop for you.
As such, there's no need to specify the event loop.

::

Expand Down Expand Up @@ -250,6 +250,10 @@ different ways::
In a crucial way, the behavior of ``await`` depends on the type of object
being awaited.

^^^^^^^^^^^^^^
Awaiting tasks
^^^^^^^^^^^^^^

Awaiting a task will cede control from the current task or coroutine to
the event loop.
In the process of relinquishing control, a few important things happen.
Expand Down Expand Up @@ -281,6 +285,10 @@ This is a basic, yet reliable mental model.
In practice, the control handoffs are slightly more complex, but not by much.
In part 2, we'll walk through the details that make this possible.

^^^^^^^^^^^^^^^^^^^
Awaiting coroutines
^^^^^^^^^^^^^^^^^^^

**Unlike tasks, awaiting a coroutine does not hand control back to the event
loop!**
Wrapping a coroutine in a task first, then awaiting that would cede
Expand Down Expand Up @@ -347,8 +355,10 @@ The design intentionally trades off some conceptual clarity around usage of
``await`` for improved performance.
Each time a task is awaited, control needs to be passed all the way up the
call stack to the event loop.
That might sound minor, but in a large program with many ``await`` statements and a deep
call stack, that overhead can add up to a meaningful performance drag.
Then, the event loop needs to manage its internal state and work through
its processing logic to resume the next job.
That might sound minor, but in a large program with many ``await``\ s, that
overhead can add up to a non-negligible performance drag.

------------------------------------------------
A conceptual overview part 2: the nuts and bolts
Expand All @@ -364,7 +374,8 @@ and how to make your own asynchronous operators.
The inner workings of coroutines
================================

:mod:`!asyncio` leverages four components to pass around control.
:mod:`!asyncio` leverages four components of Python to pass
around control.

:meth:`coroutine.send(arg) <generator.send>` is the method used to start or
resume a coroutine.
Expand Down Expand Up @@ -448,9 +459,9 @@ That might sound odd to you. You might be thinking:
That causes the error: ``SyntaxError: yield from not allowed in a coroutine.``
This was intentionally designed for the sake of simplicity -- mandating only
one way of using coroutines.
Despite that, ``yield from`` and ``await`` effectively do the same thing.
Initially ``yield`` was barred as well, but was re-accepted to allow for
async generators.
Despite that, ``yield from`` and ``await`` effectively do the same thing.

=======
Futures
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,7 @@ and classes for traversing abstract syntax trees:
The minimum supported version for ``feature_version`` is now ``(3, 7)``.
The ``optimize`` argument was added.

.. versionadded:: next
.. versionadded:: 3.15
Added the *module* parameter.


Expand Down
2 changes: 1 addition & 1 deletion Doc/library/decimal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ Constants
Specification that this implementation complies with.
See https://speleotrove.com/decimal/decarith.html for the specification.

.. versionadded:: next
.. versionadded:: 3.15


The following constants are only relevant for the C module. They
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ are always available. They are listed here in alphabetical order.
``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` can now be passed in flags to enable
support for top-level ``await``, ``async for``, and ``async with``.

.. versionadded:: next
.. versionadded:: 3.15
Added the *module* parameter.


Expand Down
2 changes: 1 addition & 1 deletion Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ The :mod:`functools` module defines the following functions:

.. versionadded:: 3.8

.. versionchanged:: next
.. versionchanged:: 3.15
Added support of non-:term:`descriptor` callables.


Expand Down
4 changes: 2 additions & 2 deletions Doc/library/importlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ ABC hierarchy::
.. versionchanged:: 3.5
Made the method static.

.. versionadded:: next
.. versionadded:: 3.15
Added the *fullname* parameter.


Expand Down Expand Up @@ -1048,7 +1048,7 @@ find and load modules.
:meth:`PathFinder.invalidate_caches` invalidates :class:`NamespacePath`,
forcing the path value to be recomputed next time it is accessed.

.. versionadded:: next
.. versionadded:: 3.15


.. class:: SourceFileLoader(fullname, path)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ Retrieving source code
.. versionchanged:: 3.5
Documentation strings are now inherited if not overridden.

.. versionchanged:: next
.. versionchanged:: 3.15
Added parameters *inherit_class_doc* and *fallback_to_class_doc*.

Documentation strings on :class:`~functools.cached_property`
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/math.integer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.. module:: math.integer
:synopsis: Integer-specific mathematics functions.

.. versionadded:: next
.. versionadded:: 3.15

--------------

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ the following functions from the :mod:`math.integer` module:
Floats with integral values (like ``5.0``) are no longer accepted in the
:func:`factorial` function.

.. deprecated:: next
.. deprecated:: 3.15
These aliases are :term:`soft deprecated` in favor of the
:mod:`math.integer` functions.

Expand Down
14 changes: 7 additions & 7 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ features:

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next
.. versionadded:: 3.15


.. class:: statx_result
Expand Down Expand Up @@ -3661,7 +3661,7 @@ features:

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next
.. versionadded:: 3.15


.. data:: STATX_TYPE
Expand Down Expand Up @@ -3690,7 +3690,7 @@ features:

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next
.. versionadded:: 3.15

.. data:: AT_STATX_FORCE_SYNC

Expand All @@ -3700,7 +3700,7 @@ features:

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next
.. versionadded:: 3.15

.. data:: AT_STATX_DONT_SYNC

Expand All @@ -3709,7 +3709,7 @@ features:

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next
.. versionadded:: 3.15

.. data:: AT_STATX_SYNC_AS_STAT

Expand All @@ -3721,7 +3721,7 @@ features:

.. availability:: Linux >= 4.11 with glibc >= 2.28.

.. versionadded:: next
.. versionadded:: 3.15


.. data:: AT_NO_AUTOMOUNT
Expand All @@ -3733,7 +3733,7 @@ features:

.. availability:: Linux.

.. versionadded:: next
.. versionadded:: 3.15


.. function:: statvfs(path)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/stat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,4 @@ meaning of these constants.
STATX_ATTR_DAX
STATX_ATTR_WRITE_ATOMIC

.. versionadded:: next
.. versionadded:: 3.15
2 changes: 1 addition & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,7 @@ objects.

Taking all bytes is a zero-copy operation.

.. versionadded:: next
.. versionadded:: 3.15

See the :ref:`What's New <whatsnew315-bytearray-take-bytes>` entry for
common code patterns which can be optimized with
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/symtable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Generating Symbol Tables
It is needed to unambiguous :ref:`filter <warning-filter>` syntax warnings
by module name.

.. versionadded:: next
.. versionadded:: 3.15
Added the *module* parameter.


Expand Down
4 changes: 2 additions & 2 deletions Doc/library/unicodedata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ following functions:
>>> unicodedata.isxidstart('0')
False

.. versionadded:: next
.. versionadded:: 3.15


.. function:: isxidcontinue(chr, /)
Expand All @@ -171,7 +171,7 @@ following functions:
>>> unicodedata.isxidcontinue(' ')
False

.. versionadded:: next
.. versionadded:: 3.15


.. function:: decomposition(chr, /)
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ Available Functions
.. versionchanged:: 3.6
Add the *source* parameter.

.. versionchanged:: next
.. versionchanged:: 3.15
If no module is passed, test the filter regular expression against
module names created from the path, not only the path itself.

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/winreg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,6 @@ integer handle, and also disconnect the Windows handle from the handle object.
will automatically close *key* when control leaves the :keyword:`with` block.


.. versionchanged:: next
.. versionchanged:: 3.15
Handle objects are now compared by their underlying Windows handle value
instead of object identity for equality comparisons.
2 changes: 1 addition & 1 deletion Doc/library/xml.dom.pulldom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ given point) or to make use of the :func:`DOMEventStream.expandNode` method
and switch to DOM-related processing.


.. class:: PullDom(documentFactory=None)
.. class:: PullDOM(documentFactory=None)

Subclass of :class:`xml.sax.handler.ContentHandler`.

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/xml.etree.elementtree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ Functions
.. versionchanged:: 3.13
Added the :meth:`!close` method.

.. versionchanged:: next
.. versionchanged:: 3.15
A :exc:`ResourceWarning` is now emitted if the iterator opened a file
and is not explicitly closed.

Expand Down
10 changes: 0 additions & 10 deletions Include/cpython/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ Py_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObje
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
PyObject *mp, PyObject *key, PyObject *defaultobj);

// Inserts `key` with a value `default_value`, if `key` is not already present
// in the dictionary. If `result` is not NULL, then the value associated
// with `key` is returned in `*result` (either the existing value, or the now
// inserted `default_value`).
// Returns:
// -1 on error
// 0 if `key` was not present and `default_value` was inserted
// 1 if `key` was present and `default_value` was not inserted
PyAPI_FUNC(int) PyDict_SetDefaultRef(PyObject *mp, PyObject *key, PyObject *default_value, PyObject **result);

/* Get the number of items of a dictionary. */
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
PyDictObject *mp;
Expand Down
Loading
Loading