Skip to content

Commit d12ad7b

Browse files
committed
Merge remote-tracking branch 'origin/3.13' into backport-a10152f-3.13
2 parents 400617f + 2fd8f03 commit d12ad7b

File tree

243 files changed

+4071
-1985
lines changed

Some content is hidden

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

243 files changed

+4071
-1985
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,20 @@ jobs:
208208
fail-fast: false
209209
matrix:
210210
os:
211-
- windows-latest
211+
- windows-2022
212212
arch:
213213
- x64
214214
free-threading:
215215
- false
216216
- true
217217
include:
218-
- os: windows-latest # FIXME(diegorusso): change to os: windows-aarch64
218+
- os: windows-2022 # FIXME(diegorusso): change to os: windows-aarch64
219219
arch: arm64
220220
free-threading: false
221-
- os: windows-latest # FIXME(diegorusso): change to os: windows-aarch64
221+
- os: windows-2022 # FIXME(diegorusso): change to os: windows-aarch64
222222
arch: arm64
223223
free-threading: true
224-
- os: windows-latest
224+
- os: windows-2022
225225
arch: Win32
226226
free-threading: false
227227
uses: ./.github/workflows/reusable-windows.yml
@@ -307,7 +307,10 @@ jobs:
307307
fail-fast: false
308308
matrix:
309309
os: [ubuntu-24.04]
310-
openssl_ver: [3.0.15, 3.1.7, 3.2.3, 3.3.2]
310+
# Keep 1.1.1w in our list despite it being upstream EOL and otherwise
311+
# unsupported as it most resembles other 1.1.1-work-a-like ssl APIs
312+
# supported by important vendors such as AWS-LC.
313+
openssl_ver: [1.1.1w, 3.0.15, 3.1.7, 3.2.3, 3.3.2]
311314
env:
312315
OPENSSL_VER: ${{ matrix.openssl_ver }}
313316
MULTISSL_DIR: ${{ github.workspace }}/multissl

.github/workflows/jit.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ jobs:
7070
include:
7171
- target: i686-pc-windows-msvc/msvc
7272
architecture: Win32
73-
runner: windows-latest
73+
runner: windows-2022
7474
compiler: msvc
7575
- target: x86_64-pc-windows-msvc/msvc
7676
architecture: x64
77-
runner: windows-latest
77+
runner: windows-2022
7878
compiler: msvc
7979
- target: aarch64-pc-windows-msvc/msvc
8080
architecture: ARM64
81-
runner: windows-latest
81+
runner: windows-2022
8282
compiler: msvc
8383
- target: x86_64-apple-darwin/clang
8484
architecture: x86_64

.github/workflows/reusable-windows-msi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717
jobs:
1818
build:
1919
name: installer for ${{ inputs.arch }}
20-
runs-on: windows-latest
20+
runs-on: windows-2022
2121
timeout-minutes: 60
2222
env:
2323
ARCH: ${{ inputs.arch }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ iOS/testbed/Python.xcframework/ios-*/lib
8080
iOS/testbed/Python.xcframework/ios-*/Python.framework
8181
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
8282
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
83-
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
8483
Mac/Makefile
8584
Mac/PythonLauncher/Info.plist
8685
Mac/PythonLauncher/Makefile

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ repos:
1010
name: Run Ruff (lint) on Lib/test/
1111
args: [--exit-non-zero-on-fix]
1212
files: ^Lib/test/
13+
- id: ruff
14+
name: Run Ruff (lint) on Tools/i18n/
15+
args: [--exit-non-zero-on-fix, --config=Tools/i18n/.ruff.toml]
16+
files: ^Tools/i18n/
1317
- id: ruff
1418
name: Run Ruff (lint) on Argument Clinic
1519
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
1620
files: ^Tools/clinic/|Lib/test/test_clinic.py
21+
- id: ruff
22+
name: Run Ruff (lint) on Tools/peg_generator/
23+
args: [--exit-non-zero-on-fix, --config=Tools/peg_generator/.ruff.toml]
24+
files: ^Tools/peg_generator/
1725
- id: ruff-format
1826
name: Run Ruff (format) on Doc/
1927
args: [--check]

.ruff.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Default settings for Ruff in CPython
2+
3+
# PYTHON_FOR_REGEN
4+
target-version = "py310"
5+
6+
# PEP 8
7+
line-length = 79
8+
9+
# Enable automatic fixes by default.
10+
# To override this, use ``fix = false`` in a subdirectory's config file
11+
# or ``--no-fix`` on the command line.
12+
fix = true

Android/android.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,10 @@ def ci(context):
737737
# Prove the package is self-contained by using it to run the tests.
738738
shutil.unpack_archive(package_path, temp_dir)
739739

740-
# Arguments are similar to --fast-ci, but in single-process mode.
740+
# Randomization is disabled because order-dependent failures are
741+
# much less likely to pass on a rerun in single-process mode.
741742
launcher_args = ["--managed", "maxVersion", "-v"]
742-
test_args = [
743-
"--single-process", "--fail-env-changed", "--rerun", "--slowest",
744-
"--verbose3", "-u", "all,-cpu", "--timeout=600"
745-
]
743+
test_args = ["--fast-ci", "--single-process", "--no-randomize"]
746744
run(
747745
["./android.py", "test", *launcher_args, "--", *test_args],
748746
cwd=temp_dir

Doc/.ruff.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
extend = "../.ruff.toml" # Inherit the project-wide settings
2+
13
target-version = "py312" # Align with the version in oldest_supported_sphinx
2-
fix = true
3-
output-format = "full"
4-
line-length = 79
54
extend-exclude = [
65
"includes/*",
76
# Temporary exclusions:

Doc/c-api/init.rst

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,11 @@ Initializing and finalizing the interpreter
447447
freed. Some memory allocated by extension modules may not be freed. Some
448448
extensions may not work properly if their initialization routine is called more
449449
than once; this can happen if an application calls :c:func:`Py_Initialize` and
450-
:c:func:`Py_FinalizeEx` more than once.
450+
:c:func:`Py_FinalizeEx` more than once. :c:func:`Py_FinalizeEx` must not be
451+
called recursively from within itself. Therefore, it must not be called by
452+
any code that may be run as part of the interpreter shutdown process, such
453+
as :py:mod:`atexit` handlers, object finalizers, or any code that may be run
454+
while flushing the stdout and stderr files.
451455
452456
.. audit-event:: cpython._PySys_ClearAuditHooks "" c.Py_FinalizeEx
453457
@@ -1074,6 +1078,37 @@ thread, where the CPython global runtime was originally initialized.
10741078
The only exception is if :c:func:`exec` will be called immediately
10751079
after.
10761080
1081+
.. _cautions-regarding-runtime-finalization:
1082+
1083+
Cautions regarding runtime finalization
1084+
---------------------------------------
1085+
1086+
In the late stage of :term:`interpreter shutdown`, after attempting to wait for
1087+
non-daemon threads to exit (though this can be interrupted by
1088+
:class:`KeyboardInterrupt`) and running the :mod:`atexit` functions, the runtime
1089+
is marked as *finalizing*: :c:func:`Py_IsFinalizing` and
1090+
:func:`sys.is_finalizing` return true. At this point, only the *finalization
1091+
thread* that initiated finalization (typically the main thread) is allowed to
1092+
acquire the :term:`GIL`.
1093+
1094+
If any thread, other than the finalization thread, attempts to acquire the GIL
1095+
during finalization, either explicitly via :c:func:`PyGILState_Ensure`,
1096+
:c:macro:`Py_END_ALLOW_THREADS`, :c:func:`PyEval_AcquireThread`, or
1097+
:c:func:`PyEval_AcquireLock`, or implicitly when the interpreter attempts to
1098+
reacquire it after having yielded it, the thread enters **a permanently blocked
1099+
state** where it remains until the program exits. In most cases this is
1100+
harmless, but this can result in deadlock if a later stage of finalization
1101+
attempts to acquire a lock owned by the blocked thread, or otherwise waits on
1102+
the blocked thread.
1103+
1104+
Gross? Yes. This prevents random crashes and/or unexpectedly skipped C++
1105+
finalizations further up the call stack when such threads were forcibly exited
1106+
here in CPython 3.13.7 and earlier. The CPython runtime GIL acquiring C APIs
1107+
have never had any error reporting or handling expectations at GIL acquisition
1108+
time that would've allowed for graceful exit from this situation. Changing that
1109+
would require new stable C APIs and rewriting the majority of C code in the
1110+
CPython ecosystem to use those with error handling.
1111+
10771112
10781113
High-level API
10791114
--------------
@@ -1093,6 +1128,12 @@ code, or when embedding the Python interpreter:
10931128
interpreter lock is also shared by all threads, regardless of to which
10941129
interpreter they belong.
10951130
1131+
.. versionchanged:: 3.12
1132+
1133+
:pep:`684` introduced the possibility
1134+
of a :ref:`per-interpreter GIL <per-interpreter-gil>`.
1135+
See :c:func:`Py_NewInterpreterFromConfig`.
1136+
10961137
10971138
.. c:type:: PyThreadState
10981139
@@ -1147,11 +1188,14 @@ code, or when embedding the Python interpreter:
11471188
ensues.
11481189
11491190
.. note::
1150-
Calling this function from a thread when the runtime is finalizing
1151-
will terminate the thread, even if the thread was not created by Python.
1152-
You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
1153-
check if the interpreter is in process of being finalized before calling
1154-
this function to avoid unwanted termination.
1191+
Calling this function from a thread when the runtime is finalizing will
1192+
hang the thread until the program exits, even if the thread was not
1193+
created by Python. Refer to
1194+
:ref:`cautions-regarding-runtime-finalization` for more details.
1195+
1196+
.. versionchanged:: next
1197+
Hangs the current thread, rather than terminating it, if called while the
1198+
interpreter is finalizing.
11551199
11561200
.. c:function:: PyThreadState* PyThreadState_Get()
11571201
@@ -1207,11 +1251,14 @@ with sub-interpreters:
12071251
to call arbitrary Python code. Failure is a fatal error.
12081252
12091253
.. note::
1210-
Calling this function from a thread when the runtime is finalizing
1211-
will terminate the thread, even if the thread was not created by Python.
1212-
You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
1213-
check if the interpreter is in process of being finalized before calling
1214-
this function to avoid unwanted termination.
1254+
Calling this function from a thread when the runtime is finalizing will
1255+
hang the thread until the program exits, even if the thread was not
1256+
created by Python. Refer to
1257+
:ref:`cautions-regarding-runtime-finalization` for more details.
1258+
1259+
.. versionchanged:: next
1260+
Hangs the current thread, rather than terminating it, if called while the
1261+
interpreter is finalizing.
12151262
12161263
.. c:function:: void PyGILState_Release(PyGILState_STATE)
12171264
@@ -1503,17 +1550,20 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15031550
If this thread already has the lock, deadlock ensues.
15041551
15051552
.. note::
1506-
Calling this function from a thread when the runtime is finalizing
1507-
will terminate the thread, even if the thread was not created by Python.
1508-
You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
1509-
check if the interpreter is in process of being finalized before calling
1510-
this function to avoid unwanted termination.
1553+
Calling this function from a thread when the runtime is finalizing will
1554+
hang the thread until the program exits, even if the thread was not
1555+
created by Python. Refer to
1556+
:ref:`cautions-regarding-runtime-finalization` for more details.
15111557
15121558
.. versionchanged:: 3.8
15131559
Updated to be consistent with :c:func:`PyEval_RestoreThread`,
15141560
:c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
15151561
and terminate the current thread if called while the interpreter is finalizing.
15161562
1563+
.. versionchanged:: next
1564+
Hangs the current thread, rather than terminating it, if called while the
1565+
interpreter is finalizing.
1566+
15171567
:c:func:`PyEval_RestoreThread` is a higher-level function which is always
15181568
available (even when threads have not been initialized).
15191569
@@ -1773,6 +1823,8 @@ function. You can create and destroy them using the following functions:
17731823
haven't been explicitly destroyed at that point.
17741824
17751825
1826+
.. _per-interpreter-gil:
1827+
17761828
A Per-Interpreter GIL
17771829
---------------------
17781830
@@ -1784,7 +1836,7 @@ being blocked by other interpreters or blocking any others. Thus a
17841836
single Python process can truly take advantage of multiple CPU cores
17851837
when running Python code. The isolation also encourages a different
17861838
approach to concurrency than that of just using threads.
1787-
(See :pep:`554`.)
1839+
(See :pep:`554` and :pep:`684`.)
17881840
17891841
Using an isolated interpreter requires vigilance in preserving that
17901842
isolation. That especially means not sharing any objects or mutable
@@ -2352,12 +2404,20 @@ per-object locks for :term:`free-threaded <free threading>` CPython. They are
23522404
intended to replace reliance on the :term:`global interpreter lock`, and are
23532405
no-ops in versions of Python with the global interpreter lock.
23542406
2407+
Critical sections are intended to be used for custom types implemented
2408+
in C-API extensions. They should generally not be used with built-in types like
2409+
:class:`list` and :class:`dict` because their public C-APIs
2410+
already use critical sections internally, with the notable
2411+
exception of :c:func:`PyDict_Next`, which requires critical section
2412+
to be acquired externally.
2413+
23552414
Critical sections avoid deadlocks by implicitly suspending active critical
2356-
sections and releasing the locks during calls to :c:func:`PyEval_SaveThread`.
2357-
When :c:func:`PyEval_RestoreThread` is called, the most recent critical section
2358-
is resumed, and its locks reacquired. This means the critical section API
2359-
provides weaker guarantees than traditional locks -- they are useful because
2360-
their behavior is similar to the :term:`GIL`.
2415+
sections, hence, they do not provide exclusive access such as provided by
2416+
traditional locks like :c:type:`PyMutex`. When a critical section is started,
2417+
the per-object lock for the object is acquired. If the code executed inside the
2418+
critical section calls C-API functions then it can suspend the critical section thereby
2419+
releasing the per-object lock, so other threads can acquire the per-object lock
2420+
for the same object.
23612421
23622422
The functions and structs used by the macros are exposed for cases
23632423
where C macros are not available. They should only be used as in the

Doc/c-api/long.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
4040
4141
Return a new :c:type:`PyLongObject` object from *v*, or ``NULL`` on failure.
4242
43-
The current implementation keeps an array of integer objects for all integers
44-
between ``-5`` and ``256``. When you create an int in that range you actually
45-
just get back a reference to the existing object.
43+
.. impl-detail::
44+
45+
CPython keeps an array of integer objects for all integers
46+
between ``-5`` and ``256``. When you create an int in that range
47+
you actually just get back a reference to the existing object.
4648
4749
4850
.. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v)

0 commit comments

Comments
 (0)