From a88567315a014ee6bc2c8779152b4211bbfdd338 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 23 Sep 2026 23:48:38 +0200 Subject: [PATCH] gh-154757: Remove deprecated PyEval_InitThreads() function --- Doc/c-api/interp-lifecycle.rst | 4 +-- Doc/c-api/threads.rst | 27 ------------------- Doc/data/stable_abi.dat | 1 - Doc/tools/removed-ids.txt | 1 + Doc/whatsnew/3.16.rst | 4 +++ Include/ceval.h | 2 -- ...-09-23-23-52-55.gh-issue-154757.EUVFeZ.rst | 2 ++ Misc/stable_abi.toml | 1 + Python/ceval_gil.c | 3 ++- 9 files changed, 11 insertions(+), 34 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2026-09-23-23-52-55.gh-issue-154757.EUVFeZ.rst diff --git a/Doc/c-api/interp-lifecycle.rst b/Doc/c-api/interp-lifecycle.rst index 46f5b1dd33963c..a38d8cec827746 100644 --- a/Doc/c-api/interp-lifecycle.rst +++ b/Doc/c-api/interp-lifecycle.rst @@ -74,8 +74,7 @@ The following functions can be safely called before Python is initialized: Despite their apparent similarity to some of the functions listed above, the following functions **should not be called** before the interpreter has - been initialized: :c:func:`Py_EncodeLocale`, :c:func:`PyEval_InitThreads`, and - :c:func:`Py_RunMain`. + been initialized: :c:func:`Py_EncodeLocale`, and :c:func:`Py_RunMain`. .. _global-conf-vars: @@ -355,7 +354,6 @@ Initializing and finalizing the interpreter .. c:function:: void Py_Initialize() .. index:: - single: PyEval_InitThreads() single: modules (in module sys) single: path (in module sys) pair: module; builtins diff --git a/Doc/c-api/threads.rst b/Doc/c-api/threads.rst index f48af654e7422b..70192207ecd1bb 100644 --- a/Doc/c-api/threads.rst +++ b/Doc/c-api/threads.rst @@ -577,33 +577,6 @@ C extensions. This thread's interpreter state. -.. c:function:: void PyEval_InitThreads() - - .. index:: - single: PyEval_AcquireThread() - single: PyEval_ReleaseThread() - single: PyEval_SaveThread() - single: PyEval_RestoreThread() - - Deprecated function which does nothing. - - In Python 3.6 and older, this function created the GIL if it didn't exist. - - .. versionchanged:: 3.9 - The function now does nothing. - - .. versionchanged:: 3.7 - This function is now called by :c:func:`Py_Initialize()`, so you don't - have to call it yourself anymore. - - .. versionchanged:: 3.2 - This function cannot be called before :c:func:`Py_Initialize()` anymore. - - .. deprecated:: 3.9 - - .. index:: pair: module; _thread - - .. c:function:: PyThreadState* PyEval_SaveThread() Detach the :term:`attached thread state` and return it. diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 3fbff9a0d65362..65f0e5f52bd936 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -239,7 +239,6 @@ func,PyEval_GetFuncDesc,3.2,, func,PyEval_GetFuncName,3.2,, func,PyEval_GetGlobals,3.2,, func,PyEval_GetLocals,3.2,, -func,PyEval_InitThreads,3.2,, func,PyEval_ReleaseThread,3.2,, func,PyEval_RestoreThread,3.2,, func,PyEval_SaveThread,3.2,, diff --git a/Doc/tools/removed-ids.txt b/Doc/tools/removed-ids.txt index be3c2f38f194ec..a6fb127a1e92ae 100644 --- a/Doc/tools/removed-ids.txt +++ b/Doc/tools/removed-ids.txt @@ -3,6 +3,7 @@ # Remove from here in 3.16 c-api/allocation.html: deprecated-aliases c-api/file.html: deprecated-api +c-api/threads.html: c.PyEval_InitThreads # Removed sections library/asyncio-task.html: terminating-a-task-group diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 6c38beb04e8d27..8010379323e721 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -1141,6 +1141,10 @@ Deprecated C APIs Removed C APIs -------------- +* Remove :c:func:`!PyEval_InitThreads` function which did nothing since Python + 3.7 and was deprecated since Python 3.9. + (Contributed by Victor Stinner in :gh:`154757`.) + * The :c:var:`!PyUnstable_ExecutableKinds` array, as well as the macros :c:macro:`!PyUnstable_EXECUTABLE_KIND_SKIP`, :c:macro:`!PyUnstable_EXECUTABLE_KIND_PY_FUNCTION`, diff --git a/Include/ceval.h b/Include/ceval.h index e9df8684996e23..93cf38ce6e2264 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -111,8 +111,6 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc); PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); -Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void); - PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); diff --git a/Misc/NEWS.d/next/C_API/2026-09-23-23-52-55.gh-issue-154757.EUVFeZ.rst b/Misc/NEWS.d/next/C_API/2026-09-23-23-52-55.gh-issue-154757.EUVFeZ.rst new file mode 100644 index 00000000000000..127d179e9a5286 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-09-23-23-52-55.gh-issue-154757.EUVFeZ.rst @@ -0,0 +1,2 @@ +Remove :c:func:`!PyEval_InitThreads` function which did nothing since Python +3.7 and was deprecated since Python 3.9. Patch by Victor Stinner. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index 8ae17142dcc67a..b7a1e49c8bf480 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -715,6 +715,7 @@ added = '3.2' [function.PyEval_InitThreads] added = '3.2' + abi_only = true [function.PyEval_ReleaseLock] added = '3.2' abi_only = true diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 2425bc1b39f0dc..49b2ede4ed3e60 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -550,7 +550,8 @@ _PyEval_FiniGIL(PyInterpreterState *interp) interp->ceval.gil = NULL; } -void +// Function removed in Python 3.16 limited C API, but kept in the stable ABI +PyAPI_FUNC(void) PyEval_InitThreads(void) { /* Do nothing: kept for backward compatibility */