Skip to content

Commit b4698ec

Browse files
authored
bpo-39877: Deprecate PyEval_InitThreads() (GH-18892)
Deprecated PyEval_InitThreads() and PyEval_ThreadsInitialized(). Calling PyEval_InitThreads() now does nothing.
1 parent 175a704 commit b4698ec

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

Doc/c-api/init.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,12 +842,12 @@ code, or when embedding the Python interpreter:
842842
single: PyEval_SaveThread()
843843
single: PyEval_RestoreThread()
844844
845-
Initialize and acquire the global interpreter lock. It should be called in the
846-
main thread before creating a second thread or engaging in any other thread
847-
operations such as ``PyEval_ReleaseThread(tstate)``. It is not needed before
848-
calling :c:func:`PyEval_SaveThread` or :c:func:`PyEval_RestoreThread`.
845+
Deprecated function which does nothing.
849846
850-
This is a no-op when called for a second time.
847+
In Python 3.6 and older, this function created the GIL if it didn't exist.
848+
849+
.. versionchanged:: 3.9
850+
The function now does nothing.
851851
852852
.. versionchanged:: 3.7
853853
This function is now called by :c:func:`Py_Initialize()`, so you don't
@@ -856,6 +856,8 @@ code, or when embedding the Python interpreter:
856856
.. versionchanged:: 3.2
857857
This function cannot be called before :c:func:`Py_Initialize()` anymore.
858858
859+
.. deprecated-removed:: 3.9 3.11
860+
859861
.. index:: module: _thread
860862
861863
@@ -868,6 +870,8 @@ code, or when embedding the Python interpreter:
868870
.. versionchanged:: 3.7
869871
The :term:`GIL` is now initialized by :c:func:`Py_Initialize()`.
870872
873+
.. deprecated-removed:: 3.9 3.11
874+
871875
872876
.. c:function:: PyThreadState* PyEval_SaveThread()
873877

Doc/whatsnew/3.9.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,12 @@ Deprecated
519519

520520
(Contributed by Victor Stinner in :issue:`39353`.)
521521

522+
* The :c:func:`PyEval_InitThreads` and :c:func:`PyEval_ThreadsInitialized`
523+
functions are now deprecated and will be removed in Python 3.11. Calling
524+
:c:func:`PyEval_InitThreads` now does nothing. The :term:`GIL` is initialized
525+
by :c:func:`Py_Initialize()` since Python 3.7.
526+
(Contributed by Victor Stinner in :issue:`39877`.)
527+
522528

523529
Removed
524530
=======

Include/ceval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
128128
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
129129
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
130130

131-
PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
132-
PyAPI_FUNC(void) PyEval_InitThreads(void);
131+
Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
132+
Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
133133
Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
134134
/* Py_DEPRECATED(3.2) */ PyAPI_FUNC(void) PyEval_ReleaseLock(void);
135135
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecated :c:func:`PyEval_InitThreads` and
2+
:c:func:`PyEval_ThreadsInitialized`. Calling :c:func:`PyEval_InitThreads` now
3+
does nothing.

Python/ceval.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,7 @@ _PyEval_InitThreads(PyThreadState *tstate)
241241
void
242242
PyEval_InitThreads(void)
243243
{
244-
PyThreadState *tstate = _PyThreadState_GET();
245-
246-
PyStatus status = _PyEval_InitThreads(tstate);
247-
if (_PyStatus_EXCEPTION(status)) {
248-
Py_ExitStatusException(status);
249-
}
244+
/* Do nothing: kept for backward compatibility */
250245
}
251246

252247
void

0 commit comments

Comments
 (0)