]> granicus.if.org Git - python/commitdiff
Issue #10756: atexit normalizes the exception before displaying it.
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 5 Jan 2011 03:54:25 +0000 (03:54 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 5 Jan 2011 03:54:25 +0000 (03:54 +0000)
Lib/test/test_atexit.py
Misc/NEWS
Modules/atexitmodule.c

index 8a71036fde077f5c2b59c48db39bb108665cb17d..9c7e109100e1f87c1d796f346659177c13fd3932 100644 (file)
@@ -65,6 +65,14 @@ class TestCase(unittest.TestCase):
 
         self.assertRaises(TypeError, atexit._run_exitfuncs)
 
+    def test_raise_unnormalized(self):
+        # Issue #10756: Make sure that an unnormalized exception is
+        # handled properly
+        atexit.register(lambda: 1 / 0)
+
+        self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs)
+        self.assertIn("ZeroDivisionError", self.stream.getvalue())
+
     def test_stress(self):
         a = [0]
         def inc():
index 7ce7445716a6c3cc95a82a2aa909d9bce6dd65b1..be158fe3efd79cdd6489a0038bf40d5986fb2bc5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -30,6 +30,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #10756: atexit normalizes the exception before displaying it.
+
 - Issue #10790: email.header.Header.append's charset logic now works correctly
   for charsets whose output codec is different from its input codec.
 
index 1382133e0a82606ecd90cba5c8ea24b5e1314cde..1ee7ead05f72cf2b896fb848add5d93caf343e4b 100644 (file)
@@ -72,6 +72,7 @@ atexit_callfuncs(void)
             PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
             if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {
                 PySys_WriteStderr("Error in atexit._run_exitfuncs:\n");
+                PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
                 PyErr_Display(exc_type, exc_value, exc_tb);
             }
         }