Skip to content

Commit 0ad43f5

Browse files
authored
Merge branch 'main' into minrun
2 parents a07d23c + d8994b0 commit 0ad43f5

20 files changed

+111
-23
lines changed

Doc/howto/free-threading-extensions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
C API Extension Support for Free Threading
77
******************************************
88

9-
Starting with the 3.13 release, CPython has experimental support for running
10-
with the :term:`global interpreter lock` (GIL) disabled in a configuration
9+
Starting with the 3.13 release, CPython has support for running with
10+
the :term:`global interpreter lock` (GIL) disabled in a configuration
1111
called :term:`free threading`. This document describes how to adapt C API
1212
extensions to support free threading.
1313

Doc/howto/free-threading-python.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
.. _freethreading-python-howto:
22

3-
**********************************************
4-
Python experimental support for free threading
5-
**********************************************
3+
*********************************
4+
Python support for free threading
5+
*********************************
66

7-
Starting with the 3.13 release, CPython has experimental support for a build of
7+
Starting with the 3.13 release, CPython has support for a build of
88
Python called :term:`free threading` where the :term:`global interpreter lock`
99
(GIL) is disabled. Free-threaded execution allows for full utilization of the
1010
available processing power by running threads in parallel on available CPU cores.
1111
While not all software will benefit from this automatically, programs
1212
designed with threading in mind will run faster on multi-core hardware.
1313

14-
**The free-threaded mode is experimental** and work is ongoing to improve it:
15-
expect some bugs and a substantial single-threaded performance hit.
14+
The free-threaded mode is working and continues to be improved, but
15+
there is some additional overhead in single-threaded workloads compared
16+
to the regular build. Additionally, third-party packages, in particular ones
17+
with an :term:`extension module`, may not be ready for use in a
18+
free-threaded build, and will re-enable the :term:`GIL`.
1619

1720
This document describes the implications of free threading
1821
for Python code. See :ref:`freethreading-extensions-howto` for information on
@@ -43,7 +46,7 @@ Identifying free-threaded Python
4346
================================
4447

4548
To check if the current interpreter supports free-threading, :option:`python -VV <-V>`
46-
and :data:`sys.version` contain "experimental free-threading build".
49+
and :data:`sys.version` contain "free-threading build".
4750
The new :func:`sys._is_gil_enabled` function can be used to check whether
4851
the GIL is actually disabled in the running process.
4952

Doc/library/ctypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ invalid non-\ ``NULL`` pointers would crash Python)::
882882
Thread safety without the GIL
883883
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
884884

885-
In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
885+
From Python 3.13 onward, the :term:`GIL` can be disabled on :term:`free threaded <free threading>` builds.
886886
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
887887

888888
.. code-block:: pycon

Doc/library/threading.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ CPU-bound tasks, as only one thread can execute Python bytecode at a time.
102102
Despite this, threads remain a useful tool for achieving concurrency in many
103103
scenarios.
104104

105-
As of Python 3.13, experimental :term:`free-threaded <free threading>` builds
105+
As of Python 3.13, :term:`free-threaded <free threading>` builds
106106
can disable the GIL, enabling true parallel execution of threads, but this
107107
feature is not available by default (see :pep:`703`).
108108

Doc/using/configure.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ General Options
290290

291291
.. option:: --disable-gil
292292

293-
Enables **experimental** support for running Python without the
294-
:term:`global interpreter lock` (GIL): free threading build.
293+
Enables support for running Python without the :term:`global interpreter
294+
lock` (GIL): free threading build.
295295

296296
Defines the ``Py_GIL_DISABLED`` macro and adds ``"t"`` to
297297
:data:`sys.abiflags`.

Lib/platform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ def _sys_version(sys_version=None):
11441144
# CPython
11451145
cpython_sys_version_parser = re.compile(
11461146
r'([\w.+]+)\s*' # "version<space>"
1147-
r'(?:experimental free-threading build\s+)?' # "free-threading-build<space>"
1147+
r'(?:free-threading build\s+)?' # "free-threading-build<space>"
11481148
r'\(#?([^,]+)' # "(#buildno"
11491149
r'(?:,\s*([\w ]*)' # ", builddate"
11501150
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"

Lib/test/test_capi/test_opt.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,21 @@ def testfunc(n):
13811381
# Removed guard
13821382
self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops)
13831383

1384+
def test_method_guards_removed_or_reduced(self):
1385+
def testfunc(n):
1386+
result = 0
1387+
for i in range(n):
1388+
result += test_bound_method(i)
1389+
return result
1390+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1391+
self.assertEqual(res, sum(range(TIER2_THRESHOLD)))
1392+
self.assertIsNotNone(ex)
1393+
uops = get_opnames(ex)
1394+
self.assertIn("_PUSH_FRAME", uops)
1395+
# Strength reduced version
1396+
self.assertIn("_CHECK_FUNCTION_VERSION_INLINE", uops)
1397+
self.assertNotIn("_CHECK_METHOD_VERSION", uops)
1398+
13841399
def test_jit_error_pops(self):
13851400
"""
13861401
Tests that the correct number of pops are inserted into the
@@ -2294,5 +2309,12 @@ def testfunc(n):
22942309
def global_identity(x):
22952310
return x
22962311

2312+
class TestObject:
2313+
def test(self, *args, **kwargs):
2314+
return args[0]
2315+
2316+
test_object = TestObject()
2317+
test_bound_method = TestObject.test.__get__(test_object)
2318+
22972319
if __name__ == "__main__":
22982320
unittest.main()

Lib/test/test_dict.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,38 @@ def badgen():
290290
['Cannot convert dictionary update sequence element #0 to a sequence'],
291291
)
292292

293+
def test_update_shared_keys(self):
294+
class MyClass: pass
295+
296+
# Subclass str to enable us to create an object during the
297+
# dict.update() call.
298+
class MyStr(str):
299+
def __hash__(self):
300+
return super().__hash__()
301+
302+
def __eq__(self, other):
303+
# Create an object that shares the same PyDictKeysObject as
304+
# obj.__dict__.
305+
obj2 = MyClass()
306+
obj2.a = "a"
307+
obj2.b = "b"
308+
obj2.c = "c"
309+
return super().__eq__(other)
310+
311+
obj = MyClass()
312+
obj.a = "a"
313+
obj.b = "b"
314+
315+
x = {}
316+
x[MyStr("a")] = MyStr("a")
317+
318+
# gh-132617: this previously raised "dict mutated during update" error
319+
x.update(obj.__dict__)
320+
321+
self.assertEqual(x, {
322+
MyStr("a"): "a",
323+
"b": "b",
324+
})
293325

294326
def test_fromkeys(self):
295327
self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})

Misc/NEWS.d/3.14.0a6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ variable.
13251325
.. nonce: d75n8U
13261326
.. section: Core and Builtins
13271327
1328-
Adapt :func:`reversed` for use in the free-theading build. The
1328+
Adapt :func:`reversed` for use in the free-threading build. The
13291329
:func:`reversed` is still not thread-safe in the sense that concurrent
13301330
iterations may see the same object, but they will not corrupt the
13311331
interpreter state.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove "experimental" tag from the CPython free-threading build.

0 commit comments

Comments
 (0)