diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-04 20:02:30 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-05-04 20:02:30 +0200 |
commit | 89ae6ab2a2cfece70bf55c2a314376093e6a1a41 (patch) | |
tree | 7695c65229b5132eecc4c4f7105ee249792fe832 /Python/pythonrun.c | |
parent | 937d0116fec9486da27788e281287878396742be (diff) | |
download | cpython-89ae6ab2a2cfece70bf55c2a314376093e6a1a41.tar.gz |
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.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index faaf54a0a6..1e2dd586b4 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -90,6 +90,8 @@ int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ 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 * @@ -188,6 +190,7 @@ Py_InitializeEx(int install_sigs) 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 @@ -388,15 +391,19 @@ Py_Finalize(void) * the threads created via Threading. */ call_py_exitfuncs(); - initialized = 0; - - /* Flush stdout+stderr */ - flush_std_files(); /* 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(); + /* Disable signal handling */ PyOS_FiniInterrupts(); |