Skip to content

Commit 75eed5b

Browse files
authored
gh-117929: Restore removed PyEval_InitThreads() function (#117931)
1 parent 6d0bb43 commit 75eed5b

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-7
lines changed

Doc/c-api/init.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The following functions can be safely called before Python is initialized:
5959
:c:func:`Py_Initialize`: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`,
6060
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
6161
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`,
62-
and :c:func:`Py_GetProgramName`.
62+
:c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.
6363

6464

6565
.. _global-conf-vars:
@@ -326,6 +326,7 @@ Initializing and finalizing the interpreter
326326
.. c:function:: void Py_Initialize()
327327
328328
.. index::
329+
single: PyEval_InitThreads()
329330
single: modules (in module sys)
330331
single: path (in module sys)
331332
pair: module; builtins
@@ -841,6 +842,33 @@ code, or when embedding the Python interpreter:
841842
This thread's interpreter state.
842843
843844
845+
.. c:function:: void PyEval_InitThreads()
846+
847+
.. index::
848+
single: PyEval_AcquireThread()
849+
single: PyEval_ReleaseThread()
850+
single: PyEval_SaveThread()
851+
single: PyEval_RestoreThread()
852+
853+
Deprecated function which does nothing.
854+
855+
In Python 3.6 and older, this function created the GIL if it didn't exist.
856+
857+
.. versionchanged:: 3.9
858+
The function now does nothing.
859+
860+
.. versionchanged:: 3.7
861+
This function is now called by :c:func:`Py_Initialize()`, so you don't
862+
have to call it yourself anymore.
863+
864+
.. versionchanged:: 3.2
865+
This function cannot be called before :c:func:`Py_Initialize()` anymore.
866+
867+
.. deprecated:: 3.9
868+
869+
.. index:: pair: module; _thread
870+
871+
844872
.. c:function:: PyThreadState* PyEval_SaveThread()
845873
846874
Release the global interpreter lock (if it has been created) and reset the

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/whatsnew/3.13.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,9 +2027,9 @@ Removed
20272027
added in Python 3.8 and the old macros were deprecated in Python 3.11.
20282028
(Contributed by Irit Katriel in :gh:`105111`.)
20292029

2030-
* Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
2031-
functions, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
2032-
always creates the GIL: calling ``PyEval_InitThreads()`` did nothing and
2030+
* Remove ``PyEval_ThreadsInitialized()``
2031+
function, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
2032+
always creates the GIL: calling ``PyEval_InitThreads()`` does nothing and
20332033
``PyEval_ThreadsInitialized()`` always returned non-zero.
20342034
(Contributed by Victor Stinner in :gh:`105182`.)
20352035

Include/ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc);
107107
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
108108
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
109109

110+
Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
111+
110112
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
111113
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
112114

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Restore removed :c:func:`PyEval_InitThreads` function. Patch by Victor
2+
Stinner.

Misc/stable_abi.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,6 @@
702702
added = '3.2'
703703
[function.PyEval_InitThreads]
704704
added = '3.2'
705-
abi_only = true
706705
[function.PyEval_ReleaseLock]
707706
added = '3.2'
708707
abi_only = true

Python/ceval_gil.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
512512
interp->ceval.gil = NULL;
513513
}
514514

515-
// Function removed in the Python 3.13 API but kept in the stable ABI.
516-
PyAPI_FUNC(void)
515+
void
517516
PyEval_InitThreads(void)
518517
{
519518
/* Do nothing: kept for backward compatibility */

0 commit comments

Comments
 (0)