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-44117: Remove PyEval_InitThreads() #26070

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 2 additions & 42 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ The following functions can be safely called before Python is initialized:
The following functions **should not be called** before
:c:func:`Py_Initialize`: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`,
:c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`,
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`,
:c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.
:c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`
and :c:func:`Py_GetProgramName`.


.. _global-conf-vars:
Expand Down Expand Up @@ -230,7 +230,6 @@ Initializing and finalizing the interpreter

.. index::
single: Py_SetProgramName()
single: PyEval_InitThreads()
single: modules (in module sys)
single: path (in module sys)
module: builtins
Expand Down Expand Up @@ -871,45 +870,6 @@ code, or when embedding the Python interpreter:
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-removed:: 3.9 3.11

.. index:: module: _thread


.. c:function:: int PyEval_ThreadsInitialized()

Returns a non-zero value if :c:func:`PyEval_InitThreads` has been called. This
function can be called without holding the GIL, and therefore can be used to
avoid calls to the locking API when running single-threaded.

.. 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()

Release the global interpreter lock (if it has been created) and reset the
Expand Down
2 changes: 0 additions & 2 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,6 @@ PyEval_GetFuncDesc:PyObject*:func:0:
PyEval_GetFuncName:const char*:::
PyEval_GetFuncName:PyObject*:func:0:

PyEval_InitThreads:void:::

PyEval_ReleaseLock:void:::

PyEval_ReleaseThread:void:::
Expand Down
2 changes: 0 additions & 2 deletions Doc/data/stable_abi.dat
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ function,PyEval_GetFuncDesc,3.2,
function,PyEval_GetFuncName,3.2,
function,PyEval_GetGlobals,3.2,
function,PyEval_GetLocals,3.2,
function,PyEval_InitThreads,3.2,
function,PyEval_ReleaseLock,3.2,
function,PyEval_ReleaseThread,3.2,
function,PyEval_RestoreThread,3.2,
function,PyEval_SaveThread,3.2,
function,PyEval_ThreadsInitialized,3.2,
var,PyExc_ArithmeticError,3.2,
var,PyExc_AssertionError,3.2,
var,PyExc_AttributeError,3.2,
Expand Down
32 changes: 29 additions & 3 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ Optimizations
(Contributed by Serhiy Storchaka in :issue:`28307`.)


Build and C API Changes
=======================
Build Changes
=============

* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been removed.

Deprecated
==========
Expand All @@ -116,3 +115,30 @@ Porting to Python 3.11

This section lists previously described changes and other bugfixes
that may require changes to your code.


C API Changes
=============

New Features
------------

Porting to Python 3.11
----------------------

Deprecated
----------

Removed
-------

* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been
removed.
(Contributed by Mark Shannon in :issue:`40222`.)

* Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
functions. The GIL is created by :c:func:`Py_Initialize` since Python 3.7,
and so calling explicitly ``PyEval_InitThreads()`` was useless since Python
3.7. Deprecated in 3.9, ``PyEval_InitThreads()`` did nothing and
``PyEval_ThreadsInitialized()`` already returned true.
(Contributed by Victor Stinner in :issue:`44117`.)
2 changes: 0 additions & 2 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,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(int) PyEval_ThreadsInitialized(void);
Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
/* PyEval_AcquireLock() and PyEval_ReleaseLock() are part of stable ABI.
* They will be removed from this header file in the future version.
* But they will be remained in ABI until Python 4.0.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
functions. The GIL is created by :c:func:`Py_Initialize` since Python 3.7,
and so calling explicitly ``PyEval_InitThreads()`` was useless since Python
3.7. Deprecated in 3.9, ``PyEval_InitThreads()`` did nothing and
``PyEval_ThreadsInitialized()`` already returned true.
4 changes: 0 additions & 4 deletions Misc/stable_abi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,6 @@ function PyEval_GetGlobals
added 3.2
function PyEval_GetLocals
added 3.2
function PyEval_InitThreads
added 3.2
function PyEval_ReleaseLock
added 3.2
function PyEval_ReleaseThread
Expand All @@ -611,8 +609,6 @@ function PyEval_RestoreThread
added 3.2
function PyEval_SaveThread
added 3.2
function PyEval_ThreadsInitialized
added 3.2
data PyExc_ArithmeticError
added 3.2
data PyExc_AssertionError
Expand Down
16 changes: 0 additions & 16 deletions Misc/valgrind-python.supp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@
# Will need to fix that.
#

{
Suppress leaking the GIL. Happens once per process, see comment in ceval.c.
Memcheck:Leak
fun:malloc
fun:PyThread_allocate_lock
fun:PyEval_InitThreads
}

{
Suppress leaking the GIL after a fork.
Memcheck:Leak
fun:malloc
fun:PyThread_allocate_lock
fun:PyEval_ReInitThreads
}

{
Suppress leaking the autoTLSkey. This looks like it shouldn't leak though.
Memcheck:Leak
Expand Down
2 changes: 0 additions & 2 deletions PC/python3dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ EXPORT_FUNC(PyEval_GetFuncDesc)
EXPORT_FUNC(PyEval_GetFuncName)
EXPORT_FUNC(PyEval_GetGlobals)
EXPORT_FUNC(PyEval_GetLocals)
EXPORT_FUNC(PyEval_InitThreads)
EXPORT_FUNC(PyEval_ReleaseLock)
EXPORT_FUNC(PyEval_ReleaseThread)
EXPORT_FUNC(PyEval_RestoreThread)
EXPORT_FUNC(PyEval_SaveThread)
EXPORT_FUNC(PyEval_ThreadsInitialized)
EXPORT_FUNC(PyException_GetCause)
EXPORT_FUNC(PyException_GetContext)
EXPORT_FUNC(PyException_GetTraceback)
Expand Down
21 changes: 0 additions & 21 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,12 @@ _PyEval_ThreadsInitialized(PyInterpreterState *interp)
{
return gil_created(&interp->ceval.gil);
}

int
PyEval_ThreadsInitialized(void)
{
// Fatal error if there is no current interpreter
PyInterpreterState *interp = PyInterpreterState_Get();
return _PyEval_ThreadsInitialized(interp);
}
#else
int
_PyEval_ThreadsInitialized(_PyRuntimeState *runtime)
{
return gil_created(&runtime->ceval.gil);
}

int
PyEval_ThreadsInitialized(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
return _PyEval_ThreadsInitialized(runtime);
}
#endif

PyStatus
Expand Down Expand Up @@ -360,12 +345,6 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
assert(!gil_created(gil));
}

void
PyEval_InitThreads(void)
{
/* Do nothing: kept for backward compatibility */
}

void
_PyEval_Fini(void)
{
Expand Down