Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_atexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def raise1():
def raise2():
raise SystemError

def exit():
raise SystemExit


class GeneralTest(unittest.TestCase):

Expand Down Expand Up @@ -76,6 +79,13 @@ def test_raise_unnormalized(self):
self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs)
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):
# Issue #18776: the tracebacks should be printed when errors occur.
def f():
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Extension Modules
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
called.

Expand Down
2 changes: 1 addition & 1 deletion Modules/atexitmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ atexit_callfuncs(void)
Py_XDECREF(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");
PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
PyErr_Display(exc_type, exc_value, exc_tb);
Expand Down