-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
gh-116167: Allow disabling the GIL with PYTHON_GIL=0
or -X gil=0
#116338
Conversation
!buildbot nogil |
🤖 New build scheduled with the buildbot fleet by @swtaarrs for commit ac24233 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
In free-threaded builds, running with `PYTHON_GIL=0` will now disable the GIL. Follow-up issues track work to re-enable the GIL when loading an incompatible extension, and to disable the GIL by default. In order to support re-enabling the GIL at runtime, all GIL-related data structures are initialized as usual, and disabling the GIL simply sets a flag that causes `take_gil()` and `drop_gil()` to return early. With `PYTHON_GIL=0` set, I spot-checked a few tests and small programs that don't use threads. They all seem to run fine, and very basic threaded programs work, sometimes. Trying to run the full test suite crashes pretty quickly, in `test_asyncio`.
ac24233
to
9e03999
Compare
!buildbot nogil |
🤖 New build scheduled with the buildbot fleet by @swtaarrs for commit 9e03999 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
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.
Good to add test case in this file too.
cpython/Lib/test/test_cmd_line.py
Line 896 in 72714c0
def test_int_max_str_digits(self): |
You can just add the testcase for the environment variable, still worth to adding it. |
At not for this PR, since this feature is not officially announced, but in some moment, you should write about the environment variable at https://github.com/python/cpython/blob/72714c0266ce6d39c7c7fb63f617573b8f5a3cb2/Doc/using/cmdline.rst to get user feedback. |
!buildbot nogil |
🤖 New build scheduled with the buildbot fleet by @swtaarrs for commit 4f43a87 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
What would be a good time to do that? Maybe once the GIL is disabled by default, so the description doesn't have to change? |
I would document the environment variable now, when it's added. For reference, we already document the I don't think it needs to be extensive, but should cover:
The behavior when then environment variable is not set is what's going to change in the future. We can document that later. |
After discussion in Discord, I'm also going to add a |
PYTHON_GIL=0
PYTHON_GIL=0
or -X gil=0
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.
LGTM
I've left one minor comment about an unclear test. It really isn't a blocker, as the test is passing, but it would still be nice to have a response.
This is both exciting and very scary. Congrats @swtaarrs and @colesbury :-) |
In free-threaded builds, running with
PYTHON_GIL=0
or-X gil=0
will now disable the GIL. #116322 and #116329 track follow-up work to re-enable the GIL when loading an incompatible extension, and to disable the GIL by default, respectively.In order to support re-enabling the GIL at runtime, all GIL-related data structures are initialized as usual, and disabling the GIL simply sets a flag at startup that causes
take_gil()
anddrop_gil()
to return early.With
PYTHON_GIL=0
set, I spot-checked a few tests and small programs that don't use threads. They all seem to run fine, and very basic threaded programs work, sometimes. Trying to run the full test suite crashes pretty quickly, intest_asyncio
.