https://github.com/python/cpython/commit/82936545cc82c6ae98c5a012a19726a71aeb82fd
commit: 82936545cc82c6ae98c5a012a19726a71aeb82fd
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-24T10:47:59+02:00
summary:

gh-154757: Remove deprecated PyEval_InitThreads() function (#158037)

Remove it from the C API, but keep it in the stable ABI.

files:
A Misc/NEWS.d/next/C_API/2026-09-23-23-52-55.gh-issue-154757.EUVFeZ.rst
M Doc/c-api/interp-lifecycle.rst
M Doc/c-api/threads.rst
M Doc/data/stable_abi.dat
M Doc/tools/removed-ids.txt
M Doc/whatsnew/3.16.rst
M Include/ceval.h
M Misc/stable_abi.toml
M Python/ceval_gil.c

diff --git a/Doc/c-api/interp-lifecycle.rst b/Doc/c-api/interp-lifecycle.rst
index 46f5b1dd33963c0..a38d8cec8277466 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 f48af654e7422bc..70192207ecd1bbe 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 3fbff9a0d65362b..65f0e5f52bd936b 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 be3c2f38f194ec2..a6fb127a1e92ae3 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 6c38beb04e8d27e..8010379323e7217 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 e9df8684996e23f..93cf38ce6e2264a 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 000000000000000..127d179e9a5286a
--- /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 8ae17142dcc67a0..b7a1e49c8bf4803 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 2425bc1b39f0dcc..49b2ede4ed3e60f 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 */

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to