diff options
author | Brett Simmers <swtaarrs@users.noreply.github.com> | 2024-03-11 15:02:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-11 15:02:58 (GMT) |
commit | 2731913dd5234ff5ab630a3b7f1c98ad79d4d9df (patch) | |
tree | c666bae1112581bf0fe4c23ced8d188082cbcefd /Python/sysmodule.c | |
parent | 546eb7a3be241c5abd8a83cebbbab8c71107edcf (diff) | |
download | cpython-2731913dd5234ff5ab630a3b7f1c98ad79d4d9df.zip cpython-2731913dd5234ff5ab630a3b7f1c98ad79d4d9df.tar.gz cpython-2731913dd5234ff5ab630a3b7f1c98ad79d4d9df.tar.bz2 |
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index a4161da..cd193c1 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3048,6 +3048,7 @@ static PyStructSequence_Field flags_fields[] = { {"warn_default_encoding", "-X warn_default_encoding"}, {"safe_path", "-P"}, {"int_max_str_digits", "-X int_max_str_digits"}, + {"gil", "-X gil"}, {0} }; @@ -3097,6 +3098,16 @@ set_flags_from_config(PyInterpreterState *interp, PyObject *flags) SetFlag(config->warn_default_encoding); SetFlagObj(PyBool_FromLong(config->safe_path)); SetFlag(config->int_max_str_digits); +#ifdef Py_GIL_DISABLED + if (config->enable_gil == _PyConfig_GIL_DEFAULT) { + SetFlagObj(Py_NewRef(Py_None)); + } + else { + SetFlag(config->enable_gil); + } +#else + SetFlagObj(PyLong_FromLong(1)); +#endif #undef SetFlagObj #undef SetFlag return 0; |