-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-124370: Add "howto" for free-threaded Python #124371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5b4a8aa
0252cf5
df1489e
5658fa8
ae0f637
1554fb9
3b173e0
91ec1ca
6078cfd
e02ed00
526737e
f24bdb7
a3ad6b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
.. _freethreading-python-howto: | ||
|
||
********************************* | ||
Python support for free threading | ||
********************************* | ||
********************************************** | ||
Python experimental support for free threading | ||
********************************************** | ||
|
||
Starting with the 3.13 release, CPython has experimental support for running | ||
with the :term:`global interpreter lock` (GIL) disabled in a configuration | ||
with the :term:`global interpreter lock` (GIL) disabled in a build of Python | ||
called :term:`free threading`. This document describes the implications of | ||
free threading for Python code. See :ref:`freethreading-extensions-howto` for | ||
information on how to write C extensions that support the free-threaded build. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could add a quick snapshot of the overall plan: if everything works out, eventually free threading will be the only build, etc. Also, maybe a statement about how most programmer won't need to be concerned with this, we're doing a lot to keep everyday Python programs behaving the same, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would perhaps add a note in the seealso block that refers to the PEP and adds 1 or 2 highlights:
|
||
.. seealso:: | ||
|
||
:pep:`703` – Making the Global Interpreter Lock Optional in CPython for an | ||
overall description of free-threaded Python. | ||
|
||
|
||
Installation | ||
============ | ||
|
@@ -31,7 +36,7 @@ Identifying free-threaded Python | |
|
||
The free-threaded build of CPython can optionally run with the global | ||
interpreter lock enabled, such as when :envvar:`PYTHON_GIL` is set to ``1``, | ||
or when importing an extension module that requires the GIL. | ||
or automatically when importing an extension module that requires the GIL. | ||
|
||
The :func:`sys._is_gil_enabled` function will return ``False`` if the global | ||
interpreter lock is currently disabled. This is the recommended mechanism for | ||
|
@@ -97,8 +102,11 @@ Frame objects | |
------------- | ||
|
||
It is not safe to access :ref:`frame <frame-objects>` objects from other | ||
willingc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
threads. This means that :func:`sys._current_frames` is generally not safe to | ||
use in a free-threaded build. | ||
threads and doing so may cause your program to crash . This means that | ||
:func:`sys._current_frames` is generally not safe to use in a free-threaded | ||
build. Functions like :func:`inspect.currentframe` and :func:`sys._getframe` | ||
are generally safe as long as the resulting frame object is not passed to | ||
another thread. | ||
|
||
Iterators | ||
--------- | ||
|
@@ -116,4 +124,5 @@ compared to the default GIL-enabled build. In 3.13, this overhead is about | |
40% on the `pyperformance <https://pyperformance.readthedocs.io/>`_ suite. | ||
willingc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Programs that spend most of their time in C extensions or I/O will see | ||
less of an impact. This overhead is expected to be reduced in Python | ||
3.14. | ||
3.14. We are aiming for an overhead of 10% or less on the pyperformance | ||
suite compared to the default GIL-enabled build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to switch between "free threading" and "free-threaded" kind of randomly. I can't decide if this is OK or if we should choose one and stick with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine. We also say both "multithreaded" and "multithreading" depending on the context.