diff options
| author | Marcel Plch <gmarcel.plch@gmail.com> | 2017-12-20 11:17:58 +0100 |
|---|---|---|
| committer | Antoine Pitrou <pitrou@free.fr> | 2017-12-20 11:17:58 +0100 |
| commit | 776407fe893fd42972c7e3f71423d9d86741d07c (patch) | |
| tree | 2d2a5781d83709c56d27e5815af2d7a2fc5726c0 /Lib/test/test_atexit.py | |
| parent | 19760863623b636a63ccf649107d9504c6465a92 (diff) | |
| download | cpython-git-776407fe893fd42972c7e3f71423d9d86741d07c.tar.gz | |
bpo-31901: atexit callbacks should be run at subinterpreter shutdown (#4611)
Change atexit behavior and PEP-489 multiphase init support.
Diffstat (limited to 'Lib/test/test_atexit.py')
| -rw-r--r-- | Lib/test/test_atexit.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index aa56388ef6..3105f6c378 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -2,6 +2,7 @@ import sys import unittest import io import atexit +import os from test import support from test.support import script_helper @@ -203,6 +204,24 @@ class SubinterpreterTest(unittest.TestCase): self.assertEqual(ret, 0) self.assertEqual(atexit._ncallbacks(), n) + def test_callback_on_subinterpreter_teardown(self): + # This tests if a callback is called on + # subinterpreter teardown. + expected = b"The test has passed!" + r, w = os.pipe() + + code = r"""if 1: + import os + import atexit + def callback(): + os.write({:d}, b"The test has passed!") + atexit.register(callback) + """.format(w) + ret = support.run_in_subinterp(code) + os.close(w) + self.assertEqual(os.read(r, len(expected)), expected) + os.close(r) + if __name__ == "__main__": unittest.main() |
