]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #9901: Destroying the GIL in Py_Finalize() can fail if some other
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 20 Sep 2010 20:13:48 +0000 (20:13 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 20 Sep 2010 20:13:48 +0000 (20:13 +0000)
threads are still running.  Instead, reinitialize the GIL on a second
call to Py_Initialize().

Misc/NEWS
Python/pythonrun.c

index 61279ec21040337329dc2995b0cb8dc2d275b1ba..250121f4546d087f2adbf38f324c2a06a430c915 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.2 Alpha 3?
 Core and Builtins
 -----------------
 
+- Issue #9901: Destroying the GIL in Py_Finalize() can fail if some other
+  threads are still running.  Instead, reinitialize the GIL on a second
+  call to Py_Initialize().
+
 - Issue #9252: PyImport_Import no longer uses a fromlist hack to return the
   module that was imported, but instead gets the module from sys.modules.
 
index 8f4e9f18f7e0409c801c00a320b902e0fc3404f3..a3f5d2b6673e4b62590a6920f2c25218d345621d 100644 (file)
@@ -217,8 +217,15 @@ Py_InitializeEx(int install_sigs)
         Py_FatalError("Py_Initialize: can't make first thread");
     (void) PyThreadState_Swap(tstate);
 
-    /* auto-thread-state API, if available */
 #ifdef WITH_THREAD
+    /* We can't call _PyEval_FiniThreads() in Py_Finalize 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_Finalize multiple times. */
+    _PyEval_FiniThreads();
+
+    /* Auto-thread-state API */
     _PyGILState_Init(interp, tstate);
 #endif /* WITH_THREAD */
 
@@ -514,10 +521,6 @@ Py_Finalize(void)
 
     PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
 
-#ifdef WITH_THREAD
-    _PyEval_FiniThreads();
-#endif
-
 #ifdef Py_TRACE_REFS
     /* Display addresses (& refcnts) of all objects still alive.
      * An address can be used to find the repr of the object, printed