diff Python/pythonrun.c @ 86332:19ce90930e8b 3.3

Issue #18776: atexit callbacks now display their full traceback when they raise an exception.
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 13 Oct 2013 21:53:13 +0200
parents 7de9852cdc0e
children 4c4f31a1b706 c13ef65f3dcf
line wrap: on
line diff
--- a/Python/pythonrun.c	Sun Oct 13 21:19:00 2013 +0300
+++ b/Python/pythonrun.c	Sun Oct 13 21:53:13 2013 +0200
@@ -1880,6 +1880,16 @@
 {
     PyObject *seen;
     PyObject *f = PySys_GetObject("stderr");
+    if (PyExceptionInstance_Check(value)
+        && tb != NULL && PyTraceBack_Check(tb)) {
+        /* Put the traceback on the exception, otherwise it won't get
+           displayed.  See issue #18776. */
+        PyObject *cur_tb = PyException_GetTraceback(value);
+        if (cur_tb == NULL)
+            PyException_SetTraceback(value, tb);
+        else
+            Py_DECREF(cur_tb);
+    }
     if (f == Py_None) {
         /* pass */
     }