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

Skip to content

Commit 92b9c44

Browse files
[3.13] gh-123275: Support -Xgil=1 and PYTHON_GIL=1 on non-free-threaded builds (gh-123276) (gh-123753)
gh-123275: Support `-Xgil=1` and `PYTHON_GIL=1` on non-free-threaded builds (gh-123276) (cherry picked from commit 84ad264) Co-authored-by: Peter Bierma <[email protected]>
1 parent e5568e5 commit 92b9c44

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
@@ -616,7 +616,7 @@ Miscellaneous options
616616
.. versionadded:: 3.13
617617

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

@@ -1215,13 +1215,12 @@ conflict.
12151215
.. envvar:: PYTHON_GIL
12161216

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

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

1223-
Needs Python configured with the :option:`--disable-gil` build option.
1224-
12251224
.. versionadded:: 3.13
12261225

12271226
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
@@ -1542,20 +1542,24 @@ config_wstr_to_int(const wchar_t *wstr, int *result)
15421542
static PyStatus
15431543
config_read_gil(PyConfig *config, size_t len, wchar_t first_char)
15441544
{
1545-
#ifdef Py_GIL_DISABLED
15461545
if (len == 1 && first_char == L'0') {
1546+
#ifdef Py_GIL_DISABLED
15471547
config->enable_gil = _PyConfig_GIL_DISABLE;
1548+
#else
1549+
return _PyStatus_ERR("Disabling the GIL is not supported by this build");
1550+
#endif
15481551
}
15491552
else if (len == 1 && first_char == L'1') {
1553+
#ifdef Py_GIL_DISABLED
15501554
config->enable_gil = _PyConfig_GIL_ENABLE;
1555+
#else
1556+
return _PyStatus_OK();
1557+
#endif
15511558
}
15521559
else {
15531560
return _PyStatus_ERR("PYTHON_GIL / -X gil must be \"0\" or \"1\"");
15541561
}
15551562
return _PyStatus_OK();
1556-
#else
1557-
return _PyStatus_ERR("PYTHON_GIL / -X gil are not supported by this build");
1558-
#endif
15591563
}
15601564

15611565
static PyStatus

0 commit comments

Comments
 (0)