8000 [3.6] bpo-28994: Fixed errors handling in atexit._run_exitfuncs(). (G… · python/cpython@d89dc84 · GitHub
[go: up one dir, main page]

Skip to content

Commit d89dc84

Browse files
[3.6] bpo-28994: Fixed errors handling in atexit._run_exitfuncs(). (GH-2034) (#2121)
The traceback no longer displayed for SystemExit raised in a callback registered by atexit.. (cherry picked from commit 3fd54d4)
1 parent 47c9dec commit d89dc84

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/test/test_atexit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def raise1():
2323
def raise2():
2424
raise SystemError
2525

26+
def exit():
27+
raise SystemExit
28+
2629

2730
class GeneralTest(unittest.TestCase):
2831

@@ -76,6 +79,13 @@ def test_raise_unnormalized(self):
7679
self.assertRaises(ZeroDivisionError, atexit._run_exitfuncs)
7780
self.assertIn("ZeroDivisionError", self.stream.getvalue())
7881

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+
7989
def test_print_tracebacks(self):
8090
# Issue #18776: the tracebacks should be printed when errors occur.
8191
def f():

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Core and Builtins
4949
Library
5050
-------
5151

52+
- bpo-28994: The traceback no longer displayed for SystemExit raised in
53+
a callback registered by atexit.
54+
5255
- bpo-30508: Don't log exceptions if Task/Future "cancel()" method was
5356
called.
5457

Modules/atexitmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ atexit_callfuncs(void)
9797
Py_XDECREF(exc_tb);
9898
}
9999
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
100-
if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {
100+
if (!PyErr_GivenExceptionMatches(exc_type, PyExc_SystemExit)) {
101101
PySys_WriteStderr("Error in atexit._run_exitfuncs:\n");
102102
PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
103103
PyErr_Display(exc_type, exc_value, exc_tb);

0 commit comments

Comments
 (0)
0