Skip to content

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

Merged
merged 13 commits into from
Sep 25, 2024
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
  • Loading branch information
colesbury and willingc authored Sep 24, 2024
commit 91ec1cae09cd3c94be13d8e52a212b2f62ffb718
12 changes: 6 additions & 6 deletions Doc/howto/free-threading-python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
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 build of Python
called :term:`free threading`. This document describes the implications of
Starting with the 3.13 release, CPython has experimental support for a build of Python
called :term:`free threading` where the :term:`global interpreter lock` (GIL) is disabled. 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.
Copy link
Member

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.

Copy link
Contributor Author

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.


Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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:

  • performance conscious users may wish to try the free threaded version
  • most users can safely continue to use the default CPython version
  • when free threading is no longer experimental, the versions will converge into one version for all.

Expand Down Expand Up @@ -52,12 +51,12 @@ Thread safety
=============

The free-threaded build of CPython aims to provide similar thread-safety
behavior at the Python level to the GIL-enabled build. Built-in
behavior at the Python level to the default GIL-enabled build. Built-in
types like :class:`dict`, :class:`list`, and :class:`set` use internal locks
to protect against concurrent modifications in ways that behave similarly to
the GIL. However, Python has not historically guaranteed specific behavior for
concurrent modifications to these built-in types, so this should be treated
as a description of the current implementation, not a guarantee of future
as a description of the current implementation, not a guarantee of current or future
behavior.

.. note::
Expand All @@ -82,7 +81,8 @@ multi-threaded scaling. This means that these objects are never deallocated.
This is expected to be addressed in Python 3.14 with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"addressed" how? That makes it sound like immortal objects are a problem. Are they?

`deferred reference counting <https://peps.python.org/pep-0703/#deferred-reference-counting>`_.

The objects that are immortalized are:
An object will be made immortal when a new thread is started for the first time after the main thread is running.
The following objects are immortalized:

* :ref:`function <user-defined-funcs>` objects declared at the module level
* :ref:`method <instance-methods>` descriptors
Expand Down
Loading