comparison Python/pythonrun.c @ 64857:38b0d5d0dd30

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().
author Antoine Pitrou <solipsis@pitrou.net>
date Mon, 20 Sep 2010 20:13:48 +0000
parents 557e2537c9ae
children 01b96f78fb70
comparison
equal deleted inserted replaced
64856:3cace1289de4 64857:38b0d5d0dd30
215 tstate = PyThreadState_New(interp); 215 tstate = PyThreadState_New(interp);
216 if (tstate == NULL) 216 if (tstate == NULL)
217 Py_FatalError("Py_Initialize: can't make first thread"); 217 Py_FatalError("Py_Initialize: can't make first thread");
218 (void) PyThreadState_Swap(tstate); 218 (void) PyThreadState_Swap(tstate);
219 219
220 /* auto-thread-state API, if available */
221 #ifdef WITH_THREAD 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 _PyGILState_Init(interp, tstate); 229 _PyGILState_Init(interp, tstate);
223 #endif /* WITH_THREAD */ 230 #endif /* WITH_THREAD */
224 231
225 _Py_ReadyTypes(); 232 _Py_ReadyTypes();
226 233
511 - int and float free list blocks 518 - int and float free list blocks
512 - whatever various modules and libraries allocate 519 - whatever various modules and libraries allocate
513 */ 520 */
514 521
515 PyGrammar_RemoveAccelerators(&_PyParser_Grammar); 522 PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
516
517 #ifdef WITH_THREAD
518 _PyEval_FiniThreads();
519 #endif
520 523
521 #ifdef Py_TRACE_REFS 524 #ifdef Py_TRACE_REFS
522 /* Display addresses (& refcnts) of all objects still alive. 525 /* Display addresses (& refcnts) of all objects still alive.
523 * An address can be used to find the repr of the object, printed 526 * An address can be used to find the repr of the object, printed
524 * above by _Py_PrintReferences. 527 * above by _Py_PrintReferences.