Skip to content

Commit bfa84c3

Browse files
Merge branch 'main' into fix-c-fromisoformat-empty-fraction-tz
2 parents e03e051 + c393ab6 commit bfa84c3

344 files changed

Lines changed: 18396 additions & 9390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/reusable-emscripten.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ jobs:
6363
run: python3 Platforms/emscripten configure-build-python -- --config-cache --with-pydebug
6464
- name: "Make build Python"
6565
run: python3 Platforms/emscripten make-build-python
66+
- name: "Display build info of the build Python"
67+
run: python3 Platforms/emscripten pythoninfo-build
6668
- name: "Make dependencies"
6769
run: >-
6870
python3 Platforms/emscripten make-dependencies
6971
${{ steps.emsdk-cache.outputs.cache-hit == 'true' && '--check-up-to-date' || '' }}
70-
- name: "Configure host Python"
72+
- name: "Configure host/Emscripten Python"
7173
run: python3 Platforms/emscripten configure-host --host-runner node -- --config-cache
72-
- name: "Make host Python"
74+
- name: "Make host/Emscripten Python"
7375
run: python3 Platforms/emscripten make-host
74-
- name: "Display build info"
75-
run: python3 Platforms/emscripten run --pythoninfo
76+
- name: "Display build info of the host/Emscripten Python"
77+
run: python3 Platforms/emscripten pythoninfo-host
7678
- name: "Test"
7779
run: python3 Platforms/emscripten run --test

.github/workflows/reusable-wasi.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
timeout-minutes: 60
1717
env:
1818
WASMTIME_VERSION: 38.0.3
19-
CROSS_BUILD_PYTHON: cross-build/build
2019
CROSS_BUILD_WASI: cross-build/wasm32-wasip1
2120
steps:
2221
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -54,14 +53,16 @@ jobs:
5453
run: python3 Platforms/WASI configure-build-python -- --config-cache --with-pydebug
5554
- name: "Make build Python"
5655
run: python3 Platforms/WASI make-build-python
57-
- name: "Configure host"
56+
- name: "Display build info of the build Python"
57+
run: python3 Platforms/WASI pythoninfo-build
58+
- name: "Configure host/WASI Python"
5859
# `--with-pydebug` inferred from configure-build-python
5960
run: python3 Platforms/WASI configure-host -- --config-cache
6061
env:
6162
WASI_SDK_PATH: ${{ steps.install-wasi-sdk.outputs.wasi-sdk-path }}
62-
- name: "Make host"
63+
- name: "Make host/WASI Python"
6364
run: python3 Platforms/WASI make-host
64-
- name: "Display build info"
65-
run: make --directory "${CROSS_BUILD_WASI}" pythoninfo
65+
- name: "Display build info of the host/WASI Python"
66+
run: python3 Platforms/WASI pythoninfo-host
6667
- name: "Test"
6768
run: make --directory "${CROSS_BUILD_WASI}" test

Doc/c-api/threads.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,61 @@ a thread state that was previously attached for the current thread.
242242
.. seealso::
243243
:pep:`788`
244244

245+
.. _c-api-reuse-thread-state:
246+
247+
Reusing a thread state across repeated calls
248+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
249+
250+
Creating and destroying a :c:type:`PyThreadState` is not free, and is more
251+
expensive on a :term:`free-threaded build`. A foreign thread that calls into
252+
the interpreter many times -- for example, a worker thread in a native thread
253+
pool -- should avoid creating a fresh thread state on every entry and
254+
destroying it on every exit. Instead, set up one thread state when the thread
255+
starts (or lazily on its first call into Python), attach and detach it around
256+
each call, and tear it down once when the thread exits.
257+
258+
Manage the thread state explicitly with :c:func:`PyThreadState_New`, attaching
259+
and detaching it with :c:func:`PyEval_RestoreThread` and
260+
:c:func:`PyEval_SaveThread`. This happens in three distinct phases, at
261+
different points in the thread's life.
262+
263+
When the thread starts, create one thread state for it. ``interp`` is the
264+
target interpreter, captured by the code that created this thread while it held
265+
an attached thread state (for example via :c:func:`PyInterpreterState_Get`)::
266+
267+
PyThreadState *tstate = PyThreadState_New(interp);
268+
269+
Then, on each call into Python -- which may happen many times over the thread's
270+
life -- attach the thread state, make the Python C API calls that require it,
271+
and detach again so the thread does not hold the GIL while off doing non-Python
272+
work::
273+
274+
PyEval_RestoreThread(tstate);
275+
result = CallSomeFunction(); /* your Python C API calls go here */
276+
PyEval_SaveThread();
277+
278+
When the thread is finished calling into Python, destroy the thread state once::
279+
280+
PyEval_RestoreThread(tstate);
281+
PyThreadState_Clear(tstate);
282+
PyThreadState_DeleteCurrent();
283+
284+
The general-purpose entry points for calling in from a foreign thread --
285+
:c:func:`PyThreadState_Ensure` and the older :c:func:`PyGILState_Ensure` -- do
286+
*not* guarantee a persistent thread state: their thread-state lifetime is
287+
deliberately implementation-defined, so a matched acquire/release pair may
288+
create and destroy a thread state each time. Use :c:func:`PyThreadState_New`,
289+
as shown here, whenever you specifically want to reuse one thread state across
290+
calls.
291+
292+
The code that created the foreign thread must arrange for the shutdown sequence
293+
to run before the thread exits, and before :c:func:`Py_FinalizeEx` is called.
294+
If interpreter finalization begins first, the shutdown
295+
:c:func:`PyEval_RestoreThread` call will hang the thread rather than return (see
296+
:ref:`cautions-regarding-runtime-finalization`). If the thread exits without
297+
running the shutdown sequence, the thread state is leaked for the remainder of
298+
the process.
299+
245300
.. _c-api-attach-detach:
246301

247302
Attaching/detaching thread states

Doc/c-api/type.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ but need extra remarks for use as slots:
639639
in the following situations:
640640
641641
- The base is not variable-sized (its
642-
:c:member:`~PyTypeObject.tp_itemsize`).
642+
:c:member:`~PyTypeObject.tp_itemsize` is zero).
643643
- The requested :c:member:`PyType_Spec.basicsize` is positive,
644644
suggesting that the memory layout of the base class is known.
645645
- The requested :c:member:`PyType_Spec.basicsize` is zero,

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ Pending removal in Python 3.16
3333
* :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16.
3434
In particular, the following classes and functions are deprecated:
3535

36-
* :class:`asyncio.AbstractEventLoopPolicy`
37-
* :class:`asyncio.DefaultEventLoopPolicy`
38-
* :class:`asyncio.WindowsSelectorEventLoopPolicy`
39-
* :class:`asyncio.WindowsProactorEventLoopPolicy`
40-
* :func:`asyncio.get_event_loop_policy`
41-
* :func:`asyncio.set_event_loop_policy`
36+
* :class:`!asyncio.AbstractEventLoopPolicy`
37+
* :class:`!asyncio.DefaultEventLoopPolicy`
38+
* :class:`!asyncio.WindowsSelectorEventLoopPolicy`
39+
* :class:`!asyncio.WindowsProactorEventLoopPolicy`
40+
* :func:`!asyncio.get_event_loop_policy`
41+
* :func:`!asyncio.set_event_loop_policy`
4242

4343
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
4444
*loop_factory* to use the desired event loop implementation.

Doc/deprecations/pending-removal-in-3.17.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ Pending removal in Python 3.17
6868

6969
See :pep:`PEP 688 <688#current-options>` for more details.
7070
(Contributed by Shantanu Jain in :gh:`91896`.)
71+
72+
* :mod:`tkinter`:
73+
74+
- The :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
75+
:meth:`!trace` (an alias of :meth:`!trace_variable`),
76+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo`, deprecated since
77+
Python 3.14, are scheduled for removal in Python 3.17.
78+
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info`
79+
instead.
80+
(Contributed by Serhiy Storchaka in :gh:`120220`.)

Doc/deprecations/pending-removal-in-3.21.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ Pending removal in Python 3.21
1717
are not generated by the parser or accepted by the code generator.
1818
* The ``dims`` property of ``ast.Tuple`` will be removed in Python 3.21. Use
1919
the ``ast.Tuple.elts`` property instead.
20+
21+
* :mod:`struct`:
22+
23+
* Soft-deprecated since Python 3.15, using ``'F'`` and ``'D'`` type codes are now
24+
deprecated. These codes will be removed in Python 3.21. Use instead
25+
two-letter forms ``'Zf'`` and ``'Zd'``.

Doc/faq/design.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ In general, structured switch statements execute one block of code
263263
when an expression has a particular value or set of values.
264264
Since Python 3.10 one can easily match literal values, or constants
265265
within a namespace, with a ``match ... case`` statement.
266+
See :ref:`the specification <match>` and :ref:`the tutorial <tut-match>`
267+
for more information about :keyword:`match` statements.
266268
An older alternative is a sequence of ``if... elif... elif... else``.
267269

268270
For cases where you need to choose from a very large number of possibilities,

Doc/howto/curses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ code, all the functions described here will probably be available. The older
5252
versions of curses carried by some proprietary Unixes may not support
5353
everything, though.
5454

55-
The Windows version of Python doesn't include the :mod:`curses`
56-
module. A ported version called :pypi:`UniCurses` is available.
55+
The Windows version of Python doesn't include the :mod:`curses` module.
56+
The third-party :pypi:`windows-curses` package provides the same interface on Windows.
5757

5858

5959
The Python curses module

Doc/howto/mro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Python 2.3 Method Resolution Order
1010
The Method Resolution Order discussed here was *introduced* in Python 2.3,
1111
but it is still used in later versions -- including Python 3.
1212

13-
By `Michele Simionato <https://www.phyast.pitt.edu/~micheles/>`__.
13+
By `Michele Simionato <https://github.com/micheles>`__.
1414

1515
:Abstract:
1616

0 commit comments

Comments
 (0)