Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 69833:c892b0321d23
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:04:29 +0200 |
| parents | ce859b848879 2a19d09b08f8 |
| children | 8752a81ada2d |
line wrap: on
line diff
--- a/Python/pythonrun.c Wed May 04 17:58:00 2011 +0100 +++ b/Python/pythonrun.c Wed May 04 20:04:29 2011 +0200 @@ -93,6 +93,8 @@ int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ +PyThreadState *_Py_Finalizing = NULL; + /* PyModule_GetWarningsModule is no longer necessary as of 2.6 since _warnings is builtin. This API should not be used. */ PyObject * @@ -191,6 +193,7 @@ if (initialized) return; initialized = 1; + _Py_Finalizing = NULL; #if defined(HAVE_LANGINFO_H) && defined(HAVE_SETLOCALE) /* Set up the LC_CTYPE locale, so we can obtain @@ -395,15 +398,19 @@ * the threads created via Threading. */ call_py_exitfuncs(); + + /* Get current thread state and interpreter pointer */ + tstate = PyThreadState_GET(); + interp = tstate->interp; + + /* Remaining threads (e.g. daemon threads) will automatically exit + after taking the GIL (in PyEval_RestoreThread()). */ + _Py_Finalizing = tstate; initialized = 0; /* Flush stdout+stderr */ flush_std_files(); - /* Get current thread state and interpreter pointer */ - tstate = PyThreadState_GET(); - interp = tstate->interp; - /* Disable signal handling */ PyOS_FiniInterrupts();
