[Python-checkins] cpython: Issue #7317: Display full tracebacks when an error occurs asynchronously.

andrew.svetlov python-checkins at python.org
Sat Nov 3 14:56:23 CET 2012


http://hg.python.org/cpython/rev/a281604a5c9a
changeset:   80189:a281604a5c9a
user:        Andrew Svetlov <andrew.svetlov at gmail.com>
date:        Sat Nov 03 15:56:05 2012 +0200
summary:
  Issue #7317: Display full tracebacks when an error occurs asynchronously.

  Patch by Alon Horev with update by Alexey Kachayev.

files:
  Lib/test/test_cmd_line.py   |   2 +-
  Lib/test/test_generators.py |  21 ++++++++++-----------
  Misc/NEWS                   |   3 +++
  Python/errors.c             |  15 ++++++++-------
  4 files changed, 22 insertions(+), 19 deletions(-)


diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -310,7 +310,7 @@
         rc, out, err = assert_python_ok('-c', code)
         self.assertEqual(b'', out)
         self.assertRegex(err.decode('ascii', 'ignore'),
-                         'Exception OSError: .* ignored')
+                         'Exception ignored in.*\nOSError: .*')
 
     def test_closed_stdout(self):
         # Issue #13444: if stdout has been explicitly closed, we should
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -1728,9 +1728,7 @@
 >>> g = f()
 >>> next(g)
 >>> del g
->>> sys.stderr.getvalue().startswith(
-...     "Exception RuntimeError: 'generator ignored GeneratorExit' in "
-... )
+>>> "RuntimeError: generator ignored GeneratorExit" in sys.stderr.getvalue()
 True
 >>> sys.stderr = old
 
@@ -1840,22 +1838,23 @@
 ...     sys.stderr = io.StringIO()
 ...     class Leaker:
 ...         def __del__(self):
-...             raise RuntimeError
+...             def invoke(message):
+...                 raise RuntimeError(message)
+...             invoke("test")
 ...
 ...     l = Leaker()
 ...     del l
 ...     err = sys.stderr.getvalue().strip()
-...     err.startswith(
-...         "Exception RuntimeError: RuntimeError() in <"
-...     )
-...     err.endswith("> ignored")
-...     len(err.splitlines())
+...     "Exception ignored in" in err
+...     "RuntimeError: test" in err
+...     "Traceback" in err
+...     "in invoke" in err
 ... finally:
 ...     sys.stderr = old
 True
 True
-1
-
+True
+True
 
 
 These refleak tests should perhaps be in a testfile of their own,
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #7317: Display full tracebacks when an error occurs asynchronously.
+  Patch by Alon Horev with update by Alexey Kachayev.
+
 - Issue #16309: Make PYTHONPATH="" behavior the same as if PYTHONPATH
   not set at all.
 
diff --git a/Python/errors.c b/Python/errors.c
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -798,7 +798,12 @@
     PyErr_Fetch(&t, &v, &tb);
     f = PySys_GetObject("stderr");
     if (f != NULL && f != Py_None) {
-        PyFile_WriteString("Exception ", f);
+        if (obj) {
+            PyFile_WriteString("Exception ignored in: ", f);
+            PyFile_WriteObject(obj, f, 0);
+            PyFile_WriteString("\n", f);
+        }
+        PyTraceBack_Print(tb, f);
         if (t) {
             PyObject* moduleName;
             char* className;
@@ -828,15 +833,11 @@
                 PyFile_WriteString(className, f);
             if (v && v != Py_None) {
                 PyFile_WriteString(": ", f);
-                PyFile_WriteObject(v, f, 0);
+                PyFile_WriteObject(v, f, Py_PRINT_RAW);
             }
+            PyFile_WriteString("\n", f);
             Py_XDECREF(moduleName);
         }
-        if (obj) {
-            PyFile_WriteString(" in ", f);
-            PyFile_WriteObject(obj, f, 0);
-        }
-        PyFile_WriteString(" ignored\n", f);
         PyErr_Clear(); /* Just in case */
     }
     Py_XDECREF(t);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list