Index: Lib/test/test_atexit.py =================================================================== --- Lib/test/test_atexit.py (Revision 87484) +++ Lib/test/test_atexit.py (Arbeitskopie) @@ -23,6 +23,10 @@ def raise2(): raise SystemError +def raise_unnormalized(): + # See issue 10756 + 1 / 0 + class TestCase(unittest.TestCase): def setUp(self): self.stream = io.StringIO() @@ -65,6 +69,14 @@ self.assertRaises(TypeError, atexit._run_exitfuncs) + def test_raise_unnormalized(self): + # Issue 10756: Be sure that an unnormalized exception is + # handled properly + atexit.register(raise_unnormalized) + + self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs) + self.assertIn("ZeroDivisionError", self.stream.getvalue()) + def test_stress(self): a = [0] def inc(): Index: Modules/atexitmodule.c =================================================================== --- Modules/atexitmodule.c (Revision 87484) +++ Modules/atexitmodule.c (Arbeitskopie) @@ -72,6 +72,7 @@ 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); } }