Issue #10756: atexit normalizes the exception before displaying it.

This commit is contained in:
Victor Stinner 2011-01-05 03:54:25 +00:00
parent 29e762c941
commit 358e11d928
3 changed files with 11 additions and 0 deletions

View File

@ -65,6 +65,14 @@ class TestCase(unittest.TestCase):
self.assertRaises(TypeError, atexit._run_exitfuncs) 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): def test_stress(self):
a = [0] a = [0]
def inc(): def inc():

View File

@ -30,6 +30,8 @@ Core and Builtins
Library Library
------- -------
- Issue #10756: atexit normalizes the exception before displaying it.
- Issue #10790: email.header.Header.append's charset logic now works correctly - Issue #10790: email.header.Header.append's charset logic now works correctly
for charsets whose output codec is different from its input codec. for charsets whose output codec is different from its input codec.

View File

@ -72,6 +72,7 @@ atexit_callfuncs(void)
PyErr_Fetch(&exc_type, &exc_value, &exc_tb); PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {
PySys_WriteStderr("Error in atexit._run_exitfuncs:\n"); PySys_WriteStderr("Error in atexit._run_exitfuncs:\n");
PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
PyErr_Display(exc_type, exc_value, exc_tb); PyErr_Display(exc_type, exc_value, exc_tb);
} }
} }