comparison Python/pythonrun.c @ 56781:2abc3b4bce7c 2.6

Merged revisions 75570,75574,75624 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. ........ 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. ........ r75624 | antoine.pitrou | 2009-10-23 14:01:13 +0200 (ven., 23 oct. 2009) | 3 lines Fix Windows buildbot failure ........
author Antoine Pitrou <solipsis@pitrou.net>
date Tue, 27 Oct 2009 12:48:52 +0000
parents cb58c973985c
children 8d8c9bf2a04e
comparison
equal deleted inserted replaced
56780:4169d3cecb9d 56781:2abc3b4bce7c
15 #include "symtable.h" 15 #include "symtable.h"
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 "abstract.h"
20 21
21 #ifdef HAVE_SIGNAL_H 22 #ifdef HAVE_SIGNAL_H
22 #include <signal.h> 23 #include <signal.h>
23 #endif 24 #endif
24 25
59 PyCompilerFlags *, PyArena *); 60 PyCompilerFlags *, PyArena *);
60 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *, 61 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *,
61 PyCompilerFlags *); 62 PyCompilerFlags *);
62 static void err_input(perrdetail *); 63 static void err_input(perrdetail *);
63 static void initsigs(void); 64 static void initsigs(void);
65 static void wait_for_thread_shutdown(void);
64 static void call_sys_exitfunc(void); 66 static void call_sys_exitfunc(void);
65 static void call_ll_exitfuncs(void); 67 static void call_ll_exitfuncs(void);
66 extern void _PyUnicode_Init(void); 68 extern void _PyUnicode_Init(void);
67 extern void _PyUnicode_Fini(void); 69 extern void _PyUnicode_Fini(void);
68 70
384 PyInterpreterState *interp; 386 PyInterpreterState *interp;
385 PyThreadState *tstate; 387 PyThreadState *tstate;
386 388
387 if (!initialized) 389 if (!initialized)
388 return; 390 return;
391
392 wait_for_thread_shutdown();
389 393
390 /* The interpreter is still entirely intact at this point, and the 394 /* The interpreter is still entirely intact at this point, and the
391 * exit funcs may be relying on that. In particular, if some thread 395 * exit funcs may be relying on that. In particular, if some thread
392 * or exit func is still waiting to do an import, the import machinery 396 * or exit func is still waiting to do an import, the import machinery
393 * expects Py_IsInitialized() to return true. So don't say the 397 * expects Py_IsInitialized() to return true. So don't say the
1661 1665
1662 #ifdef WITH_THREAD 1666 #ifdef WITH_THREAD
1663 #include "pythread.h" 1667 #include "pythread.h"
1664 #endif 1668 #endif
1665 1669
1670 /* Wait until threading._shutdown completes, provided
1671 the threading module was imported in the first place.
1672 The shutdown routine will wait until all non-daemon
1673 "threading" threads have completed. */
1674 static void
1675 wait_for_thread_shutdown(void)
1676 {
1677 #ifdef WITH_THREAD
1678 PyObject *result;
1679 PyThreadState *tstate = PyThreadState_GET();
1680 PyObject *threading = PyMapping_GetItemString(tstate->interp->modules,
1681 "threading");
1682 if (threading == NULL) {
1683 /* threading not imported */
1684 PyErr_Clear();
1685 return;
1686 }
1687 result = PyObject_CallMethod(threading, "_shutdown", "");
1688 if (result == NULL)
1689 PyErr_WriteUnraisable(threading);
1690 else
1691 Py_DECREF(result);
1692 Py_DECREF(threading);
1693 #endif
1694 }
1695
1666 #define NEXITFUNCS 32 1696 #define NEXITFUNCS 32
1667 static void (*exitfuncs[NEXITFUNCS])(void); 1697 static void (*exitfuncs[NEXITFUNCS])(void);
1668 static int nexitfuncs = 0; 1698 static int nexitfuncs = 0;
1669 1699
1670 int Py_AtExit(void (*func)(void)) 1700 int Py_AtExit(void (*func)(void))