Skip to content
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

Request for Clarification on Experimental Status of Free-Threaded Builds with GIL in CPython 3.13 #124287

Closed
briensea opened this issue Sep 20, 2024 · 2 comments
Labels
docs Documentation in the Doc dir topic-free-threading

Comments

@briensea
Copy link

Documentation

I’ve been exploring the documentation on free-threaded builds in CPython 3.13, specifically around the use of the --disable-gil option during build configuration.

The documentation states:

--disable-gil enables experimental support for running Python without the Global Interpreter Lock (GIL): free-threading build.
(Source: Python 3.13 Configuration)

It also mentions that free-threaded execution:

allows for full utilization of available CPU cores by running threads in parallel. The mode is experimental, with some expected bugs and a substantial single-threaded performance hit. Free-threaded builds support optionally running with the GIL enabled at runtime using the environment variable PYTHON_GIL or the command-line option -X gil.
(Source: What's New in Python 3.13)

However, it's unclear whether a free-threaded build with the GIL enabled (either via the PYTHON_GIL environment variable or -X gil option) should still be considered experimental. My specific questions are:

  1. Is enabling the GIL at runtime (in a free-threaded build) still part of the experimental feature set, or is this a more stable pathway for Python 3.13?
  2. Are there any known limitations or issues when running a free-threaded build with the GIL enabled, in contrast to the standard GIL-enabled CPython build?

I’ve been unable to find a clear answer to this and would appreciate any additional insights or clarifications on this point.

Thank you for your time and for all the great work on Python!

@briensea briensea added the docs Documentation in the Doc dir label Sep 20, 2024
@colesbury
Copy link
Contributor

Yes, the free-threaded build is experimental including enabling the GIL at runtime.

The most important limitation is that you still need to compile C extensions specifically for the free-threaded build. Looking at https://peps.python.org/pep-0703/#backwards-compatibility:

  • Refcounting always uses biased refcounting in the free-threaded build, with the potentital associated changes in lifetimes. (Some objects may live longer than they would normally. I don't think this is likely to come up very often)
  • Mimalloc is always used so there are still the limitations on the memory allocator mentioned in the PEP

@corona10
Copy link
Member

corona10 commented Sep 21, 2024

To make an addition to Sam's comment,

IMO, everything under the --disable-gil build should be considered experimental. Every implementation detail can be changed in a future version, and even behavior details can be changed.
And the following command says everything for the status too :)

Screenshot from 2024-09-21 11-52-36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-free-threading
Projects
None yet
Development

No branches or pull requests

4 participants