mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-119132: Remove "experimental" tag from the CPython free-threading. (gh-135550)
* gh-119132: Remove "experimental" tag from the CPython free-threading build * Address code review Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> * Add NEWS.d * Regen configure.ac * Update doc * Update * Update * Update * Update Doc/howto/free-threading-python.rst Co-authored-by: Peter Bierma <zintensitydev@gmail.com> * Update ctypes.rst * Update * Update Doc/howto/free-threading-python.rst Co-authored-by: T. Wouters <thomas@python.org> * Apply suggestions from code review Co-authored-by: T. Wouters <thomas@python.org> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --------- Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: T. Wouters <thomas@python.org>
This commit is contained in:
parent
b102f091fe
commit
f079979599
11 changed files with 23 additions and 19 deletions
|
@ -6,8 +6,8 @@
|
||||||
C API Extension Support for Free Threading
|
C API Extension Support for Free Threading
|
||||||
******************************************
|
******************************************
|
||||||
|
|
||||||
Starting with the 3.13 release, CPython has experimental support for running
|
Starting with the 3.13 release, CPython has support for running with
|
||||||
with the :term:`global interpreter lock` (GIL) disabled in a configuration
|
the :term:`global interpreter lock` (GIL) disabled in a configuration
|
||||||
called :term:`free threading`. This document describes how to adapt C API
|
called :term:`free threading`. This document describes how to adapt C API
|
||||||
extensions to support free threading.
|
extensions to support free threading.
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
.. _freethreading-python-howto:
|
.. _freethreading-python-howto:
|
||||||
|
|
||||||
**********************************************
|
*********************************
|
||||||
Python experimental support for free threading
|
Python support for free threading
|
||||||
**********************************************
|
*********************************
|
||||||
|
|
||||||
Starting with the 3.13 release, CPython has experimental support for a build of
|
Starting with the 3.13 release, CPython has support for a build of
|
||||||
Python called :term:`free threading` where the :term:`global interpreter lock`
|
Python called :term:`free threading` where the :term:`global interpreter lock`
|
||||||
(GIL) is disabled. Free-threaded execution allows for full utilization of the
|
(GIL) is disabled. Free-threaded execution allows for full utilization of the
|
||||||
available processing power by running threads in parallel on available CPU cores.
|
available processing power by running threads in parallel on available CPU cores.
|
||||||
While not all software will benefit from this automatically, programs
|
While not all software will benefit from this automatically, programs
|
||||||
designed with threading in mind will run faster on multi-core hardware.
|
designed with threading in mind will run faster on multi-core hardware.
|
||||||
|
|
||||||
**The free-threaded mode is experimental** and work is ongoing to improve it:
|
The free-threaded mode is working and continues to be improved, but
|
||||||
expect some bugs and a substantial single-threaded performance hit.
|
there is some additional overhead in single-threaded workloads compared
|
||||||
|
to the regular build. Additionally, third-party packages, in particular ones
|
||||||
|
with an :term:`extension module`, may not be ready for use in a
|
||||||
|
free-threaded build, and will re-enable the :term:`GIL`.
|
||||||
|
|
||||||
This document describes the implications of free threading
|
This document describes the implications of free threading
|
||||||
for Python code. See :ref:`freethreading-extensions-howto` for information on
|
for Python code. See :ref:`freethreading-extensions-howto` for information on
|
||||||
|
@ -43,7 +46,7 @@ Identifying free-threaded Python
|
||||||
================================
|
================================
|
||||||
|
|
||||||
To check if the current interpreter supports free-threading, :option:`python -VV <-V>`
|
To check if the current interpreter supports free-threading, :option:`python -VV <-V>`
|
||||||
and :data:`sys.version` contain "experimental free-threading build".
|
and :data:`sys.version` contain "free-threading build".
|
||||||
The new :func:`sys._is_gil_enabled` function can be used to check whether
|
The new :func:`sys._is_gil_enabled` function can be used to check whether
|
||||||
the GIL is actually disabled in the running process.
|
the GIL is actually disabled in the running process.
|
||||||
|
|
||||||
|
|
|
@ -882,7 +882,7 @@ invalid non-\ ``NULL`` pointers would crash Python)::
|
||||||
Thread safety without the GIL
|
Thread safety without the GIL
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
|
From Python 3.13 onward, the :term:`GIL` can be disabled on :term:`free threaded <free threading>` builds.
|
||||||
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
|
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
|
||||||
|
|
||||||
.. code-block:: pycon
|
.. code-block:: pycon
|
||||||
|
|
|
@ -102,7 +102,7 @@ CPU-bound tasks, as only one thread can execute Python bytecode at a time.
|
||||||
Despite this, threads remain a useful tool for achieving concurrency in many
|
Despite this, threads remain a useful tool for achieving concurrency in many
|
||||||
scenarios.
|
scenarios.
|
||||||
|
|
||||||
As of Python 3.13, experimental :term:`free-threaded <free threading>` builds
|
As of Python 3.13, :term:`free-threaded <free threading>` builds
|
||||||
can disable the GIL, enabling true parallel execution of threads, but this
|
can disable the GIL, enabling true parallel execution of threads, but this
|
||||||
feature is not available by default (see :pep:`703`).
|
feature is not available by default (see :pep:`703`).
|
||||||
|
|
||||||
|
|
|
@ -290,8 +290,8 @@ General Options
|
||||||
|
|
||||||
.. option:: --disable-gil
|
.. option:: --disable-gil
|
||||||
|
|
||||||
Enables **experimental** support for running Python without the
|
Enables support for running Python without the :term:`global interpreter
|
||||||
:term:`global interpreter lock` (GIL): free threading build.
|
lock` (GIL): free threading build.
|
||||||
|
|
||||||
Defines the ``Py_GIL_DISABLED`` macro and adds ``"t"`` to
|
Defines the ``Py_GIL_DISABLED`` macro and adds ``"t"`` to
|
||||||
:data:`sys.abiflags`.
|
:data:`sys.abiflags`.
|
||||||
|
|
|
@ -1144,7 +1144,7 @@ def _sys_version(sys_version=None):
|
||||||
# CPython
|
# CPython
|
||||||
cpython_sys_version_parser = re.compile(
|
cpython_sys_version_parser = re.compile(
|
||||||
r'([\w.+]+)\s*' # "version<space>"
|
r'([\w.+]+)\s*' # "version<space>"
|
||||||
r'(?:experimental free-threading build\s+)?' # "free-threading-build<space>"
|
r'(?:free-threading build\s+)?' # "free-threading-build<space>"
|
||||||
r'\(#?([^,]+)' # "(#buildno"
|
r'\(#?([^,]+)' # "(#buildno"
|
||||||
r'(?:,\s*([\w ]*)' # ", builddate"
|
r'(?:,\s*([\w ]*)' # ", builddate"
|
||||||
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
|
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Remove "experimental" tag from the CPython free-threading build.
|
|
@ -33,7 +33,7 @@ echo. -k Attempt to kill any running Pythons before building (usually done
|
||||||
echo. automatically by the pythoncore project)
|
echo. automatically by the pythoncore project)
|
||||||
echo. --pgo Build with Profile-Guided Optimization. This flag
|
echo. --pgo Build with Profile-Guided Optimization. This flag
|
||||||
echo. overrides -c and -d
|
echo. overrides -c and -d
|
||||||
echo. --disable-gil Enable experimental support for running without the GIL.
|
echo. --disable-gil Enable support for running without the GIL.
|
||||||
echo. --test-marker Enable the test marker within the build.
|
echo. --test-marker Enable the test marker within the build.
|
||||||
echo. --regen Regenerate all opcodes, grammar and tokens.
|
echo. --regen Regenerate all opcodes, grammar and tokens.
|
||||||
echo. --experimental-jit Enable the experimental just-in-time compiler.
|
echo. --experimental-jit Enable the experimental just-in-time compiler.
|
||||||
|
|
|
@ -15,7 +15,7 @@ void _Py_InitVersion(void)
|
||||||
}
|
}
|
||||||
initialized = 1;
|
initialized = 1;
|
||||||
#ifdef Py_GIL_DISABLED
|
#ifdef Py_GIL_DISABLED
|
||||||
const char *buildinfo_format = "%.80s experimental free-threading build (%.80s) %.80s";
|
const char *buildinfo_format = "%.80s free-threading build (%.80s) %.80s";
|
||||||
#else
|
#else
|
||||||
const char *buildinfo_format = "%.80s (%.80s) %.80s";
|
const char *buildinfo_format = "%.80s (%.80s) %.80s";
|
||||||
#endif
|
#endif
|
||||||
|
|
4
configure
generated
vendored
4
configure
generated
vendored
|
@ -1826,8 +1826,8 @@ Optional Features:
|
||||||
no)
|
no)
|
||||||
--enable-profiling enable C-level code profiling with gprof (default is
|
--enable-profiling enable C-level code profiling with gprof (default is
|
||||||
no)
|
no)
|
||||||
--disable-gil enable experimental support for running without the
|
--disable-gil enable support for running without the GIL (default
|
||||||
GIL (default is no)
|
is no)
|
||||||
--enable-pystats enable internal statistics gathering (default is no)
|
--enable-pystats enable internal statistics gathering (default is no)
|
||||||
--enable-optimizations enable expensive, stable optimizations (PGO, etc.)
|
--enable-optimizations enable expensive, stable optimizations (PGO, etc.)
|
||||||
(default is no)
|
(default is no)
|
||||||
|
|
|
@ -1716,7 +1716,7 @@ ABI_THREAD=""
|
||||||
# --disable-gil
|
# --disable-gil
|
||||||
AC_MSG_CHECKING([for --disable-gil])
|
AC_MSG_CHECKING([for --disable-gil])
|
||||||
AC_ARG_ENABLE([gil],
|
AC_ARG_ENABLE([gil],
|
||||||
[AS_HELP_STRING([--disable-gil], [enable experimental support for running without the GIL (default is no)])],
|
[AS_HELP_STRING([--disable-gil], [enable support for running without the GIL (default is no)])],
|
||||||
[AS_VAR_IF([enable_gil], [yes], [disable_gil=no], [disable_gil=yes])], [disable_gil=no]
|
[AS_VAR_IF([enable_gil], [yes], [disable_gil=no], [disable_gil=yes])], [disable_gil=no]
|
||||||
)
|
)
|
||||||
AC_MSG_RESULT([$disable_gil])
|
AC_MSG_RESULT([$disable_gil])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue