Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39877: Deprecate PyEval_InitThreads() #18892

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -842,12 +842,12 @@ code, or when embedding the Python interpreter:
single: PyEval_SaveThread()
single: PyEval_RestoreThread()

Initialize and acquire the global interpreter lock. It should be called in the
main thread before creating a second thread or engaging in any other thread
operations such as ``PyEval_ReleaseThread(tstate)``. It is not needed before
calling :c:func:`PyEval_SaveThread` or :c:func:`PyEval_RestoreThread`.
Deprecated function which does nothing.

This is a no-op when called for a second time.
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
Expand All @@ -856,6 +856,8 @@ code, or when embedding the Python interpreter:
.. versionchanged:: 3.2
This function cannot be called before :c:func:`Py_Initialize()` anymore.

.. deprecated-removed:: 3.9 3.11

.. index:: module: _thread


Expand All @@ -868,6 +870,8 @@ code, or when embedding the Python interpreter:
.. versionchanged:: 3.7
The :term:`GIL` is now initialized by :c:func:`Py_Initialize()`.

.. deprecated-removed:: 3.9 3.11


.. c:function:: PyThreadState* PyEval_SaveThread()

Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ Deprecated

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

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


Removed
=======
Expand Down
4 changes: 2 additions & 2 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);

PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
PyAPI_FUNC(void) PyEval_InitThreads(void);
Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
/* Py_DEPRECATED(3.2) */ PyAPI_FUNC(void) PyEval_ReleaseLock(void);
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Deprecated :c:func:`PyEval_InitThreads` and
:c:func:`PyEval_ThreadsInitialized`. Calling :c:func:`PyEval_InitThreads` now
does nothing.
7 changes: 1 addition & 6 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,7 @@ _PyEval_InitThreads(PyThreadState *tstate)
void
PyEval_InitThreads(void)
{
PyThreadState *tstate = _PyThreadState_GET();

PyStatus status = _PyEval_InitThreads(tstate);
if (_PyStatus_EXCEPTION(status)) {
Py_ExitStatusException(status);
}
/* Do nothing: kept for backward compatibility */
}

void
Expand Down