comparison Python/pythonrun.c @ 69832:2a19d09b08f8 3.2

Issue #1856: Avoid crashes and lockups when daemon threads run while the interpreter is shutting down; instead, these threads are now killed when they try to take the GIL.
author Antoine Pitrou <solipsis@pitrou.net>
date Wed, 04 May 2011 20:02:30 +0200
parents 2caf82aee7a4
children 7089afd69a1a c892b0321d23
comparison
equal deleted inserted replaced
69829:cc7342b4e59d 69832:2a19d09b08f8
88 int Py_FrozenFlag; /* Needed by getpath.c */ 88 int Py_FrozenFlag; /* Needed by getpath.c */
89 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ 89 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
90 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ 90 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */
91 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ 91 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */
92 92
93 PyThreadState *_Py_Finalizing = NULL;
94
93 /* PyModule_GetWarningsModule is no longer necessary as of 2.6 95 /* PyModule_GetWarningsModule is no longer necessary as of 2.6
94 since _warnings is builtin. This API should not be used. */ 96 since _warnings is builtin. This API should not be used. */
95 PyObject * 97 PyObject *
96 PyModule_GetWarningsModule(void) 98 PyModule_GetWarningsModule(void)
97 { 99 {
186 extern void _Py_ReadyTypes(void); 188 extern void _Py_ReadyTypes(void);
187 189
188 if (initialized) 190 if (initialized)
189 return; 191 return;
190 initialized = 1; 192 initialized = 1;
193 _Py_Finalizing = NULL;
191 194
192 #if defined(HAVE_LANGINFO_H) && defined(HAVE_SETLOCALE) 195 #if defined(HAVE_LANGINFO_H) && defined(HAVE_SETLOCALE)
193 /* Set up the LC_CTYPE locale, so we can obtain 196 /* Set up the LC_CTYPE locale, so we can obtain
194 the locale's charset without having to switch 197 the locale's charset without having to switch
195 locales. */ 198 locales. */
386 * Note that Threading.py uses an exit func to do a join on all the 389 * Note that Threading.py uses an exit func to do a join on all the
387 * threads created thru it, so this also protects pending imports in 390 * threads created thru it, so this also protects pending imports in
388 * the threads created via Threading. 391 * the threads created via Threading.
389 */ 392 */
390 call_py_exitfuncs(); 393 call_py_exitfuncs();
391 initialized = 0;
392
393 /* Flush stdout+stderr */
394 flush_std_files();
395 394
396 /* Get current thread state and interpreter pointer */ 395 /* Get current thread state and interpreter pointer */
397 tstate = PyThreadState_GET(); 396 tstate = PyThreadState_GET();
398 interp = tstate->interp; 397 interp = tstate->interp;
398
399 /* Remaining threads (e.g. daemon threads) will automatically exit
400 after taking the GIL (in PyEval_RestoreThread()). */
401 _Py_Finalizing = tstate;
402 initialized = 0;
403
404 /* Flush stdout+stderr */
405 flush_std_files();
399 406
400 /* Disable signal handling */ 407 /* Disable signal handling */
401 PyOS_FiniInterrupts(); 408 PyOS_FiniInterrupts();
402 409
403 /* Clear type lookup cache */ 410 /* Clear type lookup cache */