Skip to content

Commit ec0082c

Browse files
authored
gh-105182: Remove PyEval_AcquireLock() and PyEval_InitThreads() (#105183)
Remove functions in the C API: * PyEval_AcquireLock() * PyEval_ReleaseLock() * PyEval_InitThreads() * PyEval_ThreadsInitialized() But keep these functions in the stable ABI. Mention "make regen-limited-abi" in "make regen-all".
1 parent 9ab587b commit ec0082c

File tree

11 files changed

+36
-105
lines changed

11 files changed

+36
-105
lines changed

Doc/c-api/init.rst

Lines changed: 1 addition & 74 deletions
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-
:c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.
62+
and :c:func:`Py_GetProgramName`.
6363

6464

6565
.. _global-conf-vars:
@@ -326,7 +326,6 @@ Initializing and finalizing the interpreter
326326
.. c:function:: void Py_Initialize()
327327
328328
.. index::
329-
single: PyEval_InitThreads()
330329
single: modules (in module sys)
331330
single: path (in module sys)
332331
pair: module; builtins
@@ -813,45 +812,6 @@ code, or when embedding the Python interpreter:
813812
this thread's interpreter state.
814813
815814
816-
.. c:function:: void PyEval_InitThreads()
817-
818-
.. index::
819-
single: PyEval_AcquireThread()
820-
single: PyEval_ReleaseThread()
821-
single: PyEval_SaveThread()
822-
single: PyEval_RestoreThread()
823-
824-
Deprecated function which does nothing.
825-
826-
In Python 3.6 and older, this function created the GIL if it didn't exist.
827-
828-
.. versionchanged:: 3.9
829-
The function now does nothing.
830-
831-
.. versionchanged:: 3.7
832-
This function is now called by :c:func:`Py_Initialize()`, so you don't
833-
have to call it yourself anymore.
834-
835-
.. versionchanged:: 3.2
836-
This function cannot be called before :c:func:`Py_Initialize()` anymore.
837-
838-
.. deprecated:: 3.9
839-
840-
.. index:: pair: module; _thread
841-
842-
843-
.. c:function:: int PyEval_ThreadsInitialized()
844-
845-
Returns a non-zero value if :c:func:`PyEval_InitThreads` has been called. This
846-
function can be called without holding the GIL, and therefore can be used to
847-
avoid calls to the locking API when running single-threaded.
848-
849-
.. versionchanged:: 3.7
850-
The :term:`GIL` is now initialized by :c:func:`Py_Initialize()`.
851-
852-
.. deprecated:: 3.9
853-
854-
855815
.. c:function:: PyThreadState* PyEval_SaveThread()
856816
857817
Release the global interpreter lock (if it has been created) and reset the
@@ -1223,39 +1183,6 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12231183
available (even when threads have not been initialized).
12241184
12251185
1226-
.. c:function:: void PyEval_AcquireLock()
1227-
1228-
Acquire the global interpreter lock. The lock must have been created earlier.
1229-
If this thread already has the lock, a deadlock ensues.
1230-
1231-
.. deprecated:: 3.2
1232-
This function does not update the current thread state. Please use
1233-
:c:func:`PyEval_RestoreThread` or :c:func:`PyEval_AcquireThread`
1234-
instead.
1235-
1236-
.. note::
1237-
Calling this function from a thread when the runtime is finalizing
1238-
will terminate the thread, even if the thread was not created by Python.
1239-
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
1240-
check if the interpreter is in process of being finalized before calling
1241-
this function to avoid unwanted termination.
1242-
1243-
.. versionchanged:: 3.8
1244-
Updated to be consistent with :c:func:`PyEval_RestoreThread`,
1245-
:c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
1246-
and terminate the current thread if called while the interpreter is finalizing.
1247-
1248-
1249-
.. c:function:: void PyEval_ReleaseLock()
1250-
1251-
Release the global interpreter lock. The lock must have been created earlier.
1252-
1253-
.. deprecated:: 3.2
1254-
This function does not update the current thread state. Please use
1255-
:c:func:`PyEval_SaveThread` or :c:func:`PyEval_ReleaseThread`
1256-
instead.
1257-
1258-
12591186
.. _sub-interpreter-support:
12601187
12611188
Sub-interpreter support

Doc/data/refcounts.dat

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,6 @@ PyErr_WarnFormat::...::
764764
PyErr_WriteUnraisable:void:::
765765
PyErr_WriteUnraisable:PyObject*:obj:0:
766766

767-
PyEval_AcquireLock:void:::
768-
769767
PyEval_AcquireThread:void:::
770768
PyEval_AcquireThread:PyThreadState*:tstate::
771769

@@ -783,10 +781,6 @@ PyEval_GetFuncDesc:PyObject*:func:0:
783781
PyEval_GetFuncName:const char*:::
784782
PyEval_GetFuncName:PyObject*:func:0:
785783

786-
PyEval_InitThreads:void:::
787-
788-
PyEval_ReleaseLock:void:::
789-
790784
PyEval_ReleaseThread:void:::
791785
PyEval_ReleaseThread:PyThreadState*:tstate::
792786

Doc/data/stable_abi.dat

Lines changed: 0 additions & 4 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,19 @@ Removed
396396
Use the new :c:type:`PyConfig` API of the :ref:`Python Initialization
397397
Configuration <init-config>` instead (:pep:`587`), added to Python 3.8.
398398
(Contributed by Victor Stinner in :gh:`105145`.)
399+
400+
* Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
401+
functions, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
402+
always creates the GIL: calling ``PyEval_InitThreads()`` did nothing and
403+
``PyEval_ThreadsInitialized()`` always returned non-zero.
404+
(Contributed by Victor Stinner in :gh:`105182`.)
405+
406+
* Remove ``PyEval_AcquireLock()`` and ``PyEval_ReleaseLock()`` functions,
407+
deprecated in Python 3.2. They didn't update the current thread state.
408+
They can be replaced with:
409+
410+
* :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread`;
411+
* low-level :c:func:`PyEval_AcquireThread` and :c:func:`PyEval_RestoreThread`;
412+
* or :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release`.
413+
414+
(Contributed by Victor Stinner in :gh:`105182`.)

Include/ceval.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ 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(int) PyEval_ThreadsInitialized(void);
111-
Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
112-
/* PyEval_AcquireLock() and PyEval_ReleaseLock() are part of stable ABI.
113-
* They will be removed from this header file in the future version.
114-
* But they will be remained in ABI until Python 4.0.
115-
*/
116-
Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
117-
Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_ReleaseLock(void);
118110
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
119111
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
120112

Makefile.pre.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,8 @@ regen-all: regen-cases regen-opcode regen-opcode-targets regen-typeslots \
13191319
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
13201320
regen-test-levenshtein regen-global-objects
13211321
@echo
1322-
@echo "Note: make regen-stdlib-module-names and make regen-configure should be run manually"
1322+
@echo "Note: make regen-stdlib-module-names, make regen-limited-abi"
1323+
@echo "and make regen-configure should be run manually"
13231324

13241325
############################################################################
13251326
# Special rules for object files
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
2+
functions, deprecated in Python 3.9. Patch by Victor Stinner.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove ``PyEval_AcquireLock()`` and ``PyEval_ReleaseLock()`` functions,
2+
deprecated in Python 3.2. Patch by Victor Stinner.

Misc/stable_abi.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@
664664
added = '3.2'
665665
[function.PyEval_AcquireLock]
666666
added = '3.2'
667+
abi_only = true
667668
[function.PyEval_AcquireThread]
668669
added = '3.2'
669670
[function.PyEval_CallFunction]
@@ -697,8 +698,10 @@
697698
added = '3.2'
698699
[function.PyEval_InitThreads]
699700
added = '3.2'
701+
abi_only = true
700702
[function.PyEval_ReleaseLock]
701703
added = '3.2'
704+
abi_only = true
702705
[function.PyEval_ReleaseThread]
703706
added = '3.2'
704707
[function.PyEval_RestoreThread]
@@ -707,6 +710,7 @@
707710
added = '3.2'
708711
[function.PyEval_ThreadsInitialized]
709712
added = '3.2'
713+
abi_only = true
710714
[data.PyExc_ArithmeticError]
711715
added = '3.2'
712716
[data.PyExc_AssertionError]

Misc/valgrind-python.supp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@
4646
# Will need to fix that.
4747
#
4848

49-
{
50-
Suppress leaking the GIL. Happens once per process, see comment in ceval.c.
51-
Memcheck:Leak
52-
fun:malloc
53-
fun:PyThread_allocate_lock
54-
fun:PyEval_InitThreads
55-
}
56-
5749
{
5850
Suppress leaking the GIL after a fork.
5951
Memcheck:Leak

Python/ceval_gil.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ _PyEval_ThreadsInitialized(void)
496496
return gil_created(gil);
497497
}
498498

499-
int
499+
// Function removed in the Python 3.13 API but kept in the stable ABI.
500+
PyAPI_FUNC(int)
500501
PyEval_ThreadsInitialized(void)
501502
{
502503
return _PyEval_ThreadsInitialized();
@@ -584,7 +585,8 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
584585
interp->ceval.gil = NULL;
585586
}
586587

587-
void
588+
// Function removed in the Python 3.13 API but kept in the stable ABI.
589+
PyAPI_FUNC(void)
588590
PyEval_InitThreads(void)
589591
{
590592
/* Do nothing: kept for backward compatibility */
@@ -597,7 +599,9 @@ _PyEval_Fini(void)
597599
_Py_PrintSpecializationStats(1);
598600
#endif
599601
}
600-
void
602+
603+
// Function removed in the Python 3.13 API but kept in the stable ABI.
604+
PyAPI_FUNC(void)
601605
PyEval_AcquireLock(void)
602606
{
603607
PyThreadState *tstate = _PyThreadState_GET();
@@ -606,7 +610,8 @@ PyEval_AcquireLock(void)
606610
take_gil(tstate);
607611
}
608612

609-
void
613+
// Function removed in the Python 3.13 API but kept in the stable ABI.
614+
PyAPI_FUNC(void)
610615
PyEval_ReleaseLock(void)
611616
{
612617
PyThreadState *tstate = _PyThreadState_GET();

0 commit comments

Comments
 (0)