]> granicus.if.org Git - python/commitdiff
Issue #10756: atexit normalizes the exception before displaying it. Patch by
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 15 May 2011 16:57:44 +0000 (18:57 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 15 May 2011 16:57:44 +0000 (18:57 +0200)
Andreas Stührk.

Backport a fix already applied to Python 3.2+ (4a82be47a948 + 5060a92a8597).

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 c41e475cc94cbd3961cf2fa4080d6dd572d089a1..521a2a0c4630e55515d259a83e58e8f9b3a585f0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -72,6 +72,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10756: atexit normalizes the exception before displaying it. Patch by
+  Andreas Stührk.
+
 - Issue #8650: Make zlib module 64-bit clean. compress(), decompress() and
   their incremental counterparts now raise OverflowError if given an input
   larger than 4GB, instead of silently truncating the input and returning
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);
             }
         }