From 358e11d928ae4d3386c17eb0b48e7602029fec06 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 5 Jan 2011 03:54:25 +0000 Subject: Issue #10756: atexit normalizes the exception before displaying it. --- Lib/test/test_atexit.py | 8 ++++++++ Misc/NEWS | 2 ++ Modules/atexitmodule.c | 1 + 3 files changed, 11 insertions(+) diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index 8a71036..9c7e109 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -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(): diff --git a/Misc/NEWS b/Misc/NEWS index 7ce7445..be158fe 100644 --- 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. diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c index 1382133..1ee7ead 100644 --- a/Modules/atexitmodule.c +++ b/Modules/atexitmodule.c @@ -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); } } -- cgit v0.12