gh-116167: Allow disabling the GIL with `PYTHON_GIL=0` or `-X gil=0` by swtaarrs · Pull Request #116338 · python/cpython

@swtaarrs

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

corona10

@swtaarrs swtaarrs marked this pull request as ready for review

March 5, 2024 22:56

colesbury

@swtaarrs

@swtaarrs

@swtaarrs

@swtaarrs

@swtaarrs swtaarrs changed the title gh-116167: Allow disabling the GIL with PYTHON_GIL=0 gh-116167: Allow disabling the GIL with PYTHON_GIL=0 or -X gil=0

Mar 7, 2024

@swtaarrs

@swtaarrs

@swtaarrs swtaarrs marked this pull request as ready for review

March 7, 2024 22:29

ericsnowcurrently

erlend-aasland

corona10

@swtaarrs

colesbury

@python python locked as spam and limited conversation to collaborators

Mar 11, 2024