File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import io
44import atexit
55from test import support
6+ from test .support import script_helper
67
78### helpers
89def h1 ():
@@ -152,6 +153,21 @@ def test_bound_methods(self):
152153 atexit ._run_exitfuncs ()
153154 self .assertEqual (l , [5 ])
154155
156+ def test_shutdown (self ):
157+ # Actually test the shutdown mechanism in a subprocess
158+ code = """if 1:
159+ import atexit
160+
161+ def f(msg):
162+ print(msg)
163+
164+ atexit.register(f, "one")
165+ atexit.register(f, "two")
166+ """
167+ res = script_helper .assert_python_ok ("-c" , code )
168+ self .assertEqual (res .out .decode ().splitlines (), ["two" , "one" ])
169+ self .assertFalse (res .err )
170+
155171
156172@support .cpython_only
157173class SubinterpreterTest (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -2086,6 +2086,8 @@ _Py_FatalInitError(_PyInitError err)
20862086/* For the atexit module. */
20872087void _Py_PyAtExit (void (* func )(void ))
20882088{
2089+ /* Guard against API misuse (see bpo-17852) */
2090+ assert (_PyRuntime .pyexitfunc == NULL || _PyRuntime .pyexitfunc == func );
20892091 _PyRuntime .pyexitfunc = func ;
20902092}
20912093
You can’t perform that action at this time.
0 commit comments