]> granicus.if.org Git - python/commitdiff
Revert "bpo-36356: Destroy the GIL at exit (GH-12453)" (GH613006)
authorVictor Stinner <vstinner@redhat.com>
Mon, 29 Apr 2019 11:04:07 +0000 (13:04 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Apr 2019 11:04:07 +0000 (13:04 +0200)
This reverts commit b36e5d627d4232a01850707eb78a5067f3fd77f4.

Include/ceval.h
Include/internal/pycore_ceval.h
Modules/main.c
Python/ceval.c
Python/pylifecycle.c

index 98e873d2c8b234abf1c89d6c08ef30bd0bdcf5d4..11283c0a570b7e3358928aea3fcdb74e5cbdebf0 100644 (file)
@@ -192,6 +192,9 @@ PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
 
 PyAPI_FUNC(int)  PyEval_ThreadsInitialized(void);
 PyAPI_FUNC(void) PyEval_InitThreads(void);
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(void) _PyEval_FiniThreads(void);
+#endif /* !Py_LIMITED_API */
 PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2);
 PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */;
 PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
index ae3d83239227f2998f0060871ff4ff82c2ab1600..0bb19f1aa3b6423f69d47ea257d100077c58a6bb 100644 (file)
@@ -54,9 +54,6 @@ struct _ceval_runtime_state {
 
 PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *);
 
-PyAPI_FUNC(void) _PyEval_FiniThreads(void);
-PyAPI_FUNC(void) _PyEval_FiniThreads2(void);
-
 #ifdef __cplusplus
 }
 #endif
index f77bbd2f41c44278800c18bbb5f736908fa292c3..68f0b99c9fbbf407703ed5c1444f6f5c405bd6bd 100644 (file)
@@ -1,7 +1,6 @@
 /* Python interpreter main program */
 
 #include "Python.h"
-#include "pycore_ceval.h"   /* _PyEval_FiniThreads2() */
 #include "pycore_coreconfig.h"
 #include "pycore_pylifecycle.h"
 #include "pycore_pymem.h"
@@ -526,15 +525,15 @@ done:
 
 /* --- pymain_main() ---------------------------------------------- */
 
-/* Free global variables which cannot be freed in Py_Finalize():
-   configuration options set before Py_Initialize() which should
-   remain valid after Py_Finalize(), since
-   Py_Initialize()-Py_Finalize() can be called multiple times. */
 static void
 pymain_free(void)
 {
     _PyImport_Fini2();
-    _PyEval_FiniThreads2();
+
+    /* Free global variables which cannot be freed in Py_Finalize():
+       configuration options set before Py_Initialize() which should
+       remain valid after Py_Finalize(), since
+       Py_Initialize()-Py_Finalize() can be called multiple times. */
     _PyPathConfig_ClearGlobal();
     _Py_ClearStandardStreamEncoding();
     _Py_ClearArgcArgv();
index 5480fbacaf4d74a5358faa4ee3efe342750bb1d1..ccd0427a142936a27089b692eb66ef81023cdc05 100644 (file)
@@ -188,19 +188,8 @@ PyEval_InitThreads(void)
     }
 }
 
-
 void
 _PyEval_FiniThreads(void)
-{
-    if (_PyRuntime.ceval.pending.lock != NULL) {
-        PyThread_free_lock(_PyRuntime.ceval.pending.lock);
-        _PyRuntime.ceval.pending.lock = NULL;
-    }
-}
-
-
-void
-_PyEval_FiniThreads2(void)
 {
     if (!gil_created()) {
         return;
@@ -208,6 +197,11 @@ _PyEval_FiniThreads2(void)
 
     destroy_gil();
     assert(!gil_created());
+
+    if (_PyRuntime.ceval.pending.lock != NULL) {
+        PyThread_free_lock(_PyRuntime.ceval.pending.lock);
+        _PyRuntime.ceval.pending.lock = NULL;
+    }
 }
 
 static inline void
index 0836e18f9d1ce7801b116dc623a2989f5fdf4a34..d93fe065558aa39bbc499c16363114631342922f 100644 (file)
@@ -4,9 +4,8 @@
 
 #include "Python-ast.h"
 #undef Yield   /* undefine macro conflicting with <winbase.h> */
-#include "pycore_ceval.h"   /* _PyEval_FiniThreads() */
-#include "pycore_context.h"
 #include "pycore_coreconfig.h"
+#include "pycore_context.h"
 #include "pycore_fileutils.h"
 #include "pycore_hamt.h"
 #include "pycore_pathconfig.h"
@@ -556,11 +555,12 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
         return _Py_INIT_ERR("can't make first thread");
     (void) PyThreadState_Swap(tstate);
 
-    /* Destroying the GIL in Py_FinalizeEx might fail when it is being
-       referenced from another running thread (see bpo-9901).
+    /* We can't call _PyEval_FiniThreads() in Py_FinalizeEx because
+       destroying the GIL might fail when it is being referenced from
+       another running thread (see issue #9901).
        Instead we destroy the previously created GIL here, which ensures
        that we can call Py_Initialize / Py_FinalizeEx multiple times. */
-    _PyEval_FiniThreads2();
+    _PyEval_FiniThreads();
 
     /* Auto-thread-state API */
     _PyGILState_Init(runtime, interp, tstate);
@@ -1357,7 +1357,6 @@ Py_FinalizeEx(void)
 
     call_ll_exitfuncs(runtime);
 
-    _PyEval_FiniThreads();
     _PyRuntime_Finalize();
     return status;
 }