Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 56652:29b3e126c0c2 3.1
Merged revisions 75571,75576-75577 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r75571 | antoine.pitrou | 2009-10-20 23:52:47 +0200 (mar., 20 oct. 2009) | 11 lines
Merged revisions 75570 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75570 | antoine.pitrou | 2009-10-20 23:29:37 +0200 (mar., 20 oct. 2009) | 6 lines
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
fixes the problem of some exceptions being thrown at shutdown when the
interpreter is killed. Patch by Adam Olsen.
........
................
r75576 | antoine.pitrou | 2009-10-21 00:02:29 +0200 (mer., 21 oct. 2009) | 10 lines
Merged revisions 75574 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75574 | antoine.pitrou | 2009-10-20 23:59:25 +0200 (mar., 20 oct. 2009) | 4 lines
Test wouldn't work in debug mode.
We probably need a function in test_support to handle this.
........
................
r75577 | antoine.pitrou | 2009-10-21 00:05:38 +0200 (mer., 21 oct. 2009) | 3 lines
Another futile error in the previous commit :-(
................
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 20 Oct 2009 22:08:36 +0000 |
| parents | 3416721480b2 |
| children | 4bed796ee0d7 |
comparison
equal
deleted
inserted
replaced
| 56644:26007395607e | 56652:29b3e126c0c2 |
|---|---|
| 16 #include "pyarena.h" | 16 #include "pyarena.h" |
| 17 #include "ast.h" | 17 #include "ast.h" |
| 18 #include "eval.h" | 18 #include "eval.h" |
| 19 #include "marshal.h" | 19 #include "marshal.h" |
| 20 #include "osdefs.h" | 20 #include "osdefs.h" |
| 21 #include "abstract.h" | |
| 21 | 22 |
| 22 #ifdef HAVE_SIGNAL_H | 23 #ifdef HAVE_SIGNAL_H |
| 23 #include <signal.h> | 24 #include <signal.h> |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 64 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *, | 65 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *, |
| 65 PyCompilerFlags *); | 66 PyCompilerFlags *); |
| 66 static void err_input(perrdetail *); | 67 static void err_input(perrdetail *); |
| 67 static void initsigs(void); | 68 static void initsigs(void); |
| 68 static void call_py_exitfuncs(void); | 69 static void call_py_exitfuncs(void); |
| 70 static void wait_for_thread_shutdown(void); | |
| 69 static void call_ll_exitfuncs(void); | 71 static void call_ll_exitfuncs(void); |
| 70 extern void _PyUnicode_Init(void); | 72 extern void _PyUnicode_Init(void); |
| 71 extern void _PyUnicode_Fini(void); | 73 extern void _PyUnicode_Fini(void); |
| 72 extern int _PyLong_Init(void); | 74 extern int _PyLong_Init(void); |
| 73 extern void PyLong_Fini(void); | 75 extern void PyLong_Fini(void); |
| 360 PyInterpreterState *interp; | 362 PyInterpreterState *interp; |
| 361 PyThreadState *tstate; | 363 PyThreadState *tstate; |
| 362 | 364 |
| 363 if (!initialized) | 365 if (!initialized) |
| 364 return; | 366 return; |
| 367 | |
| 368 wait_for_thread_shutdown(); | |
| 365 | 369 |
| 366 /* The interpreter is still entirely intact at this point, and the | 370 /* The interpreter is still entirely intact at this point, and the |
| 367 * exit funcs may be relying on that. In particular, if some thread | 371 * exit funcs may be relying on that. In particular, if some thread |
| 368 * or exit func is still waiting to do an import, the import machinery | 372 * or exit func is still waiting to do an import, the import machinery |
| 369 * expects Py_IsInitialized() to return true. So don't say the | 373 * expects Py_IsInitialized() to return true. So don't say the |
| 2057 | 2061 |
| 2058 (*pyexitfunc)(); | 2062 (*pyexitfunc)(); |
| 2059 PyErr_Clear(); | 2063 PyErr_Clear(); |
| 2060 } | 2064 } |
| 2061 | 2065 |
| 2066 /* Wait until threading._shutdown completes, provided | |
| 2067 the threading module was imported in the first place. | |
| 2068 The shutdown routine will wait until all non-daemon | |
| 2069 "threading" threads have completed. */ | |
| 2070 static void | |
| 2071 wait_for_thread_shutdown(void) | |
| 2072 { | |
| 2073 #ifdef WITH_THREAD | |
| 2074 PyObject *result; | |
| 2075 PyThreadState *tstate = PyThreadState_GET(); | |
| 2076 PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, | |
| 2077 "threading"); | |
| 2078 if (threading == NULL) { | |
| 2079 /* threading not imported */ | |
| 2080 PyErr_Clear(); | |
| 2081 return; | |
| 2082 } | |
| 2083 result = PyObject_CallMethod(threading, "_shutdown", ""); | |
| 2084 if (result == NULL) { | |
| 2085 PyErr_WriteUnraisable(threading); | |
| 2086 } | |
| 2087 else { | |
| 2088 Py_DECREF(result); | |
| 2089 } | |
| 2090 Py_DECREF(threading); | |
| 2091 #endif | |
| 2092 } | |
| 2093 | |
| 2062 #define NEXITFUNCS 32 | 2094 #define NEXITFUNCS 32 |
| 2063 static void (*exitfuncs[NEXITFUNCS])(void); | 2095 static void (*exitfuncs[NEXITFUNCS])(void); |
| 2064 static int nexitfuncs = 0; | 2096 static int nexitfuncs = 0; |
| 2065 | 2097 |
| 2066 int Py_AtExit(void (*func)(void)) | 2098 int Py_AtExit(void (*func)(void)) |
