File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ What's New in Python 3.2 Alpha 3?
10
10
Core and Builtins
11
11
-----------------
12
12
13
+ - Issue #9901: Destroying the GIL in Py_Finalize() can fail if some other
14
+ threads are still running. Instead, reinitialize the GIL on a second
15
+ call to Py_Initialize().
16
+
13
17
- Issue #9252: PyImport_Import no longer uses a fromlist hack to return the
14
18
module that was imported, but instead gets the module from sys.modules.
15
19
Original file line number Diff line number Diff line change @@ -217,8 +217,15 @@ Py_InitializeEx(int install_sigs)
217
217
Py_FatalError ("Py_Initialize: can't make first thread" );
218
218
(void ) PyThreadState_Swap (tstate );
219
219
220
- /* auto-thread-state API, if available */
221
220
#ifdef WITH_THREAD
221
+ /* We can't call _PyEval_FiniThreads() in Py_Finalize because
222
+ destroying the GIL might fail when it is being referenced from
223
+ another running thread (see issue #9901).
224
+ Instead we destroy the previously created GIL here, which ensures
225
+ that we can call Py_Initialize / Py_Finalize multiple times. */
226
+ _PyEval_FiniThreads ();
227
+
228
+ /* Auto-thread-state API */
222
229
_PyGILState_Init (interp , tstate );
223
230
#endif /* WITH_THREAD */
224
231
@@ -514,10 +521,6 @@ Py_Finalize(void)
514
521
515
522
PyGrammar_RemoveAccelerators (& _PyParser_Grammar );
516
523
517
- #ifdef WITH_THREAD
518
- _PyEval_FiniThreads ();
519
- #endif
520
-
521
524
#ifdef Py_TRACE_REFS
522
525
/* Display addresses (& refcnts) of all objects still alive.
523
526
* An address can be used to find the repr of the object, printed
You can’t perform that action at this time.
0 commit comments