]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39877: Deprecate PyEval_InitThreads() (GH-18892)
authorVictor Stinner <vstinner@python.org>
Tue, 10 Mar 2020 00:28:54 +0000 (01:28 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2020 00:28:54 +0000 (01:28 +0100)
Deprecated PyEval_InitThreads() and PyEval_ThreadsInitialized().
Calling PyEval_InitThreads() now does nothing.

Doc/c-api/init.rst
Doc/whatsnew/3.9.rst
Include/ceval.h
Misc/NEWS.d/next/C API/2020-03-10-00-18-16.bpo-39877.GOYtIm.rst [new file with mode: 0644]
Python/ceval.c

index 14049ee64205f12a61e60edd6b7aa432e66491f5..c34b1174a5913d6493c5264280d9b35e6b15f1f6 100644 (file)
@@ -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
@@ -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
 
 
@@ -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()
 
index 31a87e6566358c0564a7242a6fda42d4a53e97ad..c2328053a66aa3ec5ec2d6de703de2e6b58d5bee 100644 (file)
@@ -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
 =======
index e977fcb43ddc1782f6b124564f8ef605d2b33d52..a70c421c18d02dc391886743d48cab725182bd37 100644 (file)
@@ -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);
diff --git a/Misc/NEWS.d/next/C API/2020-03-10-00-18-16.bpo-39877.GOYtIm.rst b/Misc/NEWS.d/next/C API/2020-03-10-00-18-16.bpo-39877.GOYtIm.rst
new file mode 100644 (file)
index 0000000..e071187
--- /dev/null
@@ -0,0 +1,3 @@
+Deprecated :c:func:`PyEval_InitThreads` and
+:c:func:`PyEval_ThreadsInitialized`. Calling :c:func:`PyEval_InitThreads` now
+does nothing.
index 0ee740ace3d86c6c17457193473ac925fab787cd..380212a71aaf75205adbec8b61ed49afc4172437 100644 (file)
@@ -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