Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84ad264

Browse files
gh-123275: Support -Xgil=1 and PYTHON_GIL=1 on non-free-threaded builds (gh-123276)
1 parent 42f5243 commit 84ad264

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Doc/using/cmdline.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ Miscellaneous options
622622
.. versionadded:: 3.13
623623

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

@@ -1221,13 +1221,12 @@ conflict.
12211221
.. envvar:: PYTHON_GIL
12221222

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

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

1229-
Needs Python configured with the :option:`--disable-gil` build option.
1230-
12311230
.. versionadded:: 3.13
12321231

12331232
Debug-mode variables
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support :option:`-X gil=1 <-X>` and :envvar:`PYTHON_GIL=1 <PYTHON_GIL>` on non-free-threaded builds.

Python/initconfig.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,20 +1714,24 @@ config_wstr_to_int(const wchar_t *wstr, int *result)
17141714
static PyStatus
17151715
config_read_gil(PyConfig *config, size_t len, wchar_t first_char)
17161716
{
1717-
#ifdef Py_GIL_DISABLED
17181717
if (len == 1 && first_char == L'0') {
1718+
#ifdef Py_GIL_DISABLED
17191719
config->enable_gil = _PyConfig_GIL_DISABLE;
1720+
#else
1721+
return _PyStatus_ERR("Disabling the GIL is not supported by this build");
1722+
#endif
17201723
}
17211724
else if (len == 1 && first_char == L'1') {
1725+
#ifdef Py_GIL_DISABLED
17221726
config->enable_gil = _PyConfig_GIL_ENABLE;
1727+
#else
1728+
return _PyStatus_OK();
1729+
#endif
17231730
}
17241731
else {
17251732
return _PyStatus_ERR("PYTHON_GIL / -X gil must be \"0\" or \"1\"");
17261733
}
17271734
return _PyStatus_OK();
1728-
#else
1729-
return _PyStatus_ERR("PYTHON_GIL / -X gil are not supported by this build");
1730-
#endif
17311735
}
17321736

17331737
static PyStatus

0 commit comments

Comments
 (0)