diff options
author | Victor Stinner <vstinner@python.org> | 2020-12-15 13:34:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-15 13:34:19 (GMT) |
commit | b8fa135908d294b350cdad04e2f512327a538dee (patch) | |
tree | 25b6b1516e3f6d29c9cf3cafb71c516cbc93a3c3 /Lib/test/test_atexit.py | |
parent | 8473cf89bdbf2cb292b39c972db540504669b9cd (diff) | |
download | cpython-b8fa135908d294b350cdad04e2f512327a538dee.zip cpython-b8fa135908d294b350cdad04e2f512327a538dee.tar.gz cpython-b8fa135908d294b350cdad04e2f512327a538dee.tar.bz2 |
bpo-42639: Move atexit state to PyInterpreterState (GH-23763)
* Add _PyAtExit_Call() function and remove pyexitfunc and
pyexitmodule members of PyInterpreterState. The function
logs atexit callback errors using _PyErr_WriteUnraisableMsg().
* Add _PyAtExit_Init() and _PyAtExit_Fini() functions.
* Remove traverse, clear and free functions of the atexit module.
Co-authored-by: Dong-hee Na <donghee.na@python.org>
Diffstat (limited to 'Lib/test/test_atexit.py')
-rw-r--r-- | Lib/test/test_atexit.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index 906f96d..29faaaf 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -170,6 +170,24 @@ class GeneralTest(unittest.TestCase): self.assertEqual(res.out.decode().splitlines(), ["two", "one"]) self.assertFalse(res.err) + def test_atexit_instances(self): + # bpo-42639: It is safe to have more than one atexit instance. + code = textwrap.dedent(""" + import sys + import atexit as atexit1 + del sys.modules['atexit'] + import atexit as atexit2 + del sys.modules['atexit'] + + assert atexit2 is not atexit1 + + atexit1.register(print, "atexit1") + atexit2.register(print, "atexit2") + """) + res = script_helper.assert_python_ok("-c", code) + self.assertEqual(res.out.decode().splitlines(), ["atexit2", "atexit1"]) + self.assertFalse(res.err) + @support.cpython_only class SubinterpreterTest(unittest.TestCase): |