bpo-28994: Fixed errors handling in atexit._run_exitfuncs(). (#2034) · python/cpython@3fd54d4 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -23,6 +23,9 @@ def raise1(): | ||
23 | 23 | def raise2(): |
24 | 24 | raise SystemError |
25 | 25 | |
26 | +def exit(): | |
27 | +raise SystemExit | |
28 | + | |
26 | 29 | |
27 | 30 | class GeneralTest(unittest.TestCase): |
28 | 31 | |
@@ -76,6 +79,13 @@ def test_raise_unnormalized(self): | ||
76 | 79 | self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs) |
77 | 80 | self.assertIn("ZeroDivisionError", self.stream.getvalue()) |
78 | 81 | |
82 | +def test_exit(self): | |
83 | +# be sure a SystemExit is handled properly | |
84 | +atexit.register(exit) | |
85 | + | |
86 | +self.assertRaises(SystemExit, atexit._run_exitfuncs) | |
87 | +self.assertEqual(self.stream.getvalue(), '') | |
88 | + | |
79 | 89 | def test_print_tracebacks(self): |
80 | 90 | # Issue #18776: the tracebacks should be printed when errors occur. |
81 | 91 | def f(): |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -359,6 +359,9 @@ Extension Modules | ||
359 | 359 | Library |
360 | 360 | ------- |
361 | 361 | |
362 | +- bpo-28994: The traceback no longer displayed for SystemExit raised in | |
363 | + a callback registered by atexit. | |
364 | + | |
362 | 365 | - bpo-30508: Don't log exceptions if Task/Future "cancel()" method was |
363 | 366 | called. |
364 | 367 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -97,7 +97,7 @@ atexit_callfuncs(void) | ||
97 | 97 | Py_XDECREF(exc_tb); |
98 | 98 | } |
99 | 99 | PyErr_Fetch(&exc_type, &exc_value, &exc_tb); |
100 | -if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { | |
100 | +if (!PyErr_GivenExceptionMatches(exc_type, PyExc_SystemExit)) { | |
101 | 101 | PySys_WriteStderr("Error in atexit._run_exitfuncs:\n"); |
102 | 102 | PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb); |
103 | 103 | PyErr_Display(exc_type, exc_value, exc_tb); |