summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-04-04 22:00:45 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2011-04-04 22:00:45 +0200
commit5d55e48fae955a732707f80b70441e8404506ec9 (patch)
tree48a5e6425b2aedea5156c0fa67a116127d1a5ada /Python/pythonrun.c
parentb24bc5ab02dac375cb9ea2011ac5a5c0925214a9 (diff)
parent1c83d39fbb8299c56c35cba3a6c699c2720a2648 (diff)
downloadcpython-5d55e48fae955a732707f80b70441e8404506ec9.tar.gz
Try to fix sporadic failure in test_thread/test_threading
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 38b2ab84fb..1c36e63ac4 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -70,6 +70,8 @@ extern void _PyUnicode_Init(void);
extern void _PyUnicode_Fini(void);
extern int _PyLong_Init(void);
extern void PyLong_Fini(void);
+extern int _PyFaulthandler_Init(void);
+extern void _PyFaulthandler_Fini(void);
#ifdef WITH_THREAD
extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
@@ -286,6 +288,10 @@ Py_InitializeEx(int install_sigs)
_PyImportHooks_Init();
+ /* initialize the faulthandler module */
+ if (_PyFaulthandler_Init())
+ Py_FatalError("Py_Initialize: can't initialize faulthandler");
+
/* Initialize _warnings. */
_PyWarnings_Init();
@@ -454,6 +460,9 @@ Py_Finalize(void)
/* Destroy the database used by _PyImport_{Fixup,Find}Extension */
_PyImport_Fini();
+ /* unload faulthandler module */
+ _PyFaulthandler_Fini();
+
/* Debugging stuff */
#ifdef COUNT_ALLOCS
dump_counts(stdout);
@@ -2100,11 +2109,24 @@ cleanup:
void
Py_FatalError(const char *msg)
{
+ const int fd = fileno(stderr);
+ PyThreadState *tstate;
+
fprintf(stderr, "Fatal Python error: %s\n", msg);
fflush(stderr); /* it helps in Windows debug build */
if (PyErr_Occurred()) {
PyErr_PrintEx(0);
}
+ else {
+ tstate = _Py_atomic_load_relaxed(&_PyThreadState_Current);
+ if (tstate != NULL) {
+ fputc('\n', stderr);
+ fflush(stderr);
+ _Py_DumpTraceback(fd, tstate);
+ }
+ _PyFaulthandler_Fini();
+ }
+
#ifdef MS_WINDOWS
{
size_t len = strlen(msg);