Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ Miscellaneous options
.. versionadded:: 3.13

* :samp:`-X gil={0,1}` forces the GIL to be disabled or enabled,
respectively. Only available in builds configured with
respectively. Setting to ``0`` is only available in builds configured with
:option:`--disable-gil`. See also :envvar:`PYTHON_GIL` and
:ref:`whatsnew313-free-threaded-cpython`.

Expand Down Expand Up @@ -1221,13 +1221,12 @@ conflict.
.. envvar:: PYTHON_GIL

If this variable is set to ``1``, the global interpreter lock (GIL) will be
forced on. Setting it to ``0`` forces the GIL off.
forced on. Setting it to ``0`` forces the GIL off (needs Python configured with
the :option:`--disable-gil` build option.)

See also the :option:`-X gil <-X>` command-line option, which takes
precedence over this variable, and :ref:`whatsnew313-free-threaded-cpython`.

Needs Python configured with the :option:`--disable-gil` build option.

.. versionadded:: 3.13

Debug-mode variables
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support ``-Xgil=1`` and ``PYTHON_GIL=1`` on non-free-threaded builds.
12 changes: 8 additions & 4 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,20 +1559,24 @@ config_wstr_to_int(const wchar_t *wstr, int *result)
static PyStatus
config_read_gil(PyConfig *config, size_t len, wchar_t first_char)
{
#ifdef Py_GIL_DISABLED
if (len == 1 && first_char == L'0') {
#ifdef Py_GIL_DISABLED
config->enable_gil = _PyConfig_GIL_DISABLE;
#else
return _PyStatus_ERR("Disabling the GIL is not supported by this build");
#endif
}
else if (len == 1 && first_char == L'1') {
#ifdef Py_GIL_DISABLED
config->enable_gil = _PyConfig_GIL_ENABLE;
#else
return _PyStatus_OK();
#endif
}
else {
return _PyStatus_ERR("PYTHON_GIL / -X gil must be \"0\" or \"1\"");
}
return _PyStatus_OK();
#else
return _PyStatus_ERR("PYTHON_GIL / -X gil are not supported by this build");
#endif
}

static PyStatus
Expand Down