From 200ae3a241d84fd8b2d7a1f9bc3827807515c4b2 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Fri, 23 Aug 2024 18:29:48 -0400 Subject: [PATCH 1/5] Support -Xgil and PYTHON_GIL on non-free-threaded builds. --- Python/initconfig.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Python/initconfig.c b/Python/initconfig.c index 51897a2d0aef66..0e822890aa147f 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -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 From 012a4c9d81c7c2518f565f1340de8229dd8ec42c Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Fri, 23 Aug 2024 18:31:15 -0400 Subject: [PATCH 2/5] Add NEWS entry. --- .../2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst new file mode 100644 index 00000000000000..29eda20bc9d6bd --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst @@ -0,0 +1 @@ +Support ``-Xgil=1`` and ``PYTHON_GIL=1`` on non-free-threaded builds. From 7b3112649d268ced8e15fbe8f6c568c5d5be2525 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Fri, 23 Aug 2024 22:18:18 -0400 Subject: [PATCH 3/5] Update documentation. --- Doc/using/cmdline.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 8c70cf4263ae05..e18f78beda2c0c 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -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`. @@ -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 From f78a7e35b0377ae3aa3c643a8a64c7934cf613c9 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sat, 24 Aug 2024 10:03:11 -0400 Subject: [PATCH 4/5] Update Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst Co-authored-by: Kirill Podoprigora --- .../2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst index 29eda20bc9d6bd..ab344a8ca40e47 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst @@ -1 +1 @@ -Support ``-Xgil=1`` and ``PYTHON_GIL=1`` on non-free-threaded builds. +Support :option:`-X gil=1 <-X>` and :envvar:`PYTHON_GIL=1 ` on non-free-threaded builds. From 7d3c769ea0c976b4eb1a5fca95a27c2e1f75c27d Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sun, 25 Aug 2024 14:53:21 -0400 Subject: [PATCH 5/5] Update cmdline.rst Co-authored-by: Matt Wozniski --- Doc/using/cmdline.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index e18f78beda2c0c..c9777a52bae5ee 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -1222,7 +1222,7 @@ conflict. If this variable is set to ``1``, the global interpreter lock (GIL) will be forced on. Setting it to ``0`` forces the GIL off (needs Python configured with - the :option:`--disable-gil` build option.) + 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`.