From d0e11ec5b07c7c49061a2e4a73a0c231d9b46ad7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 15 May 2011 18:57:44 +0200 Subject: [PATCH] =?UTF-8?q?Issue=20#10756:=20atexit=20normalizes=20the=20e?= =?UTF-8?q?xception=20before=20displaying=20it.=20Patch=20by=20Andreas=20S?= =?UTF-8?q?t=C3=BChrk.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport a fix already applied to Python 3.2+ (4a82be47a948 + 5060a92a8597). --- Lib/test/test_atexit.py | 8 ++++++++ Misc/NEWS | 3 +++ Modules/atexitmodule.c | 1 + 3 files changed, 12 insertions(+) diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index 8a71036fde0..9c7e109100e 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 c41e475cc94..521a2a0c463 100644 --- 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 diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c index 1382133e0a8..1ee7ead05f7 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); } }