summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-20 20:13:48 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-20 20:13:48 (GMT)
commitb0b384b7c0333bf1183cd6f90c0a3f9edaadd6b9 (patch)
tree5e87a6a4d5896b19b6ae0113dd04165aea4d49ea /Python
parent0646b4bb77a5955407e4174e9fac56447dc958f7 (diff)
downloadcpython-b0b384b7c0333bf1183cd6f90c0a3f9edaadd6b9.zip
cpython-b0b384b7c0333bf1183cd6f90c0a3f9edaadd6b9.tar.gz
cpython-b0b384b7c0333bf1183cd6f90c0a3f9edaadd6b9.tar.bz2
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().
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 8f4e9f1..a3f5d2b 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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