gh-116167: Allow disabling the GIL with PYTHON_GIL=0 or -X gil=0 (#116338)

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.
This commit is contained in:
Brett Simmers 2024-03-11 11:02:58 -04:00 committed by GitHub
parent 546eb7a3be
commit 2731913dd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 163 additions and 1 deletions

View file

@ -523,6 +523,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
CONFIG_COMPAT['_pystats'] = 0
if support.Py_DEBUG:
CONFIG_COMPAT['run_presite'] = None
if support.Py_GIL_DISABLED:
CONFIG_COMPAT['enable_gil'] = -1
if MS_WINDOWS:
CONFIG_COMPAT.update({
'legacy_windows_stdio': 0,