Commit 3fd54d4a authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-28994: Fixed errors handling in atexit._run_exitfuncs(). (#2034)

The traceback no longer displayed for SystemExit raised in a callback registered by atexit.
parent 1dbce04d
...@@ -23,6 +23,9 @@ def raise1(): ...@@ -23,6 +23,9 @@ def raise1():
def raise2(): def raise2():
raise SystemError raise SystemError
def exit():
raise SystemExit
class GeneralTest(unittest.TestCase): class GeneralTest(unittest.TestCase):
...@@ -76,6 +79,13 @@ class GeneralTest(unittest.TestCase): ...@@ -76,6 +79,13 @@ class GeneralTest(unittest.TestCase):
self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs) self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs)
self.assertIn("ZeroDivisionError", self.stream.getvalue()) self.assertIn("ZeroDivisionError", self.stream.getvalue())
def test_exit(self):
# be sure a SystemExit is handled properly
atexit.register(exit)
self.assertRaises(SystemExit, atexit._run_exitfuncs)
self.assertEqual(self.stream.getvalue(), '')
def test_print_tracebacks(self): def test_print_tracebacks(self):
# Issue #18776: the tracebacks should be printed when errors occur. # Issue #18776: the tracebacks should be printed when errors occur.
def f(): def f():
......
...@@ -359,6 +359,9 @@ Extension Modules ...@@ -359,6 +359,9 @@ Extension Modules
Library Library
------- -------
- bpo-28994: The traceback no longer displayed for SystemExit raised in
a callback registered by atexit.
- bpo-30508: Don't log exceptions if Task/Future "cancel()" method was - bpo-30508: Don't log exceptions if Task/Future "cancel()" method was
called. called.
......
...@@ -97,7 +97,7 @@ atexit_callfuncs(void) ...@@ -97,7 +97,7 @@ atexit_callfuncs(void)
Py_XDECREF(exc_tb); Py_XDECREF(exc_tb);
} }
PyErr_Fetch(&exc_type, &exc_value, &exc_tb); PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { if (!PyErr_GivenExceptionMatches(exc_type, 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_NormalizeException(&exc_type, &exc_value, &exc_tb);
PyErr_Display(exc_type, exc_value, exc_tb); PyErr_Display(exc_type, exc_value, exc_tb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment