summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMarcel Plch <gmarcel.plch@gmail.com>2017-12-20 10:17:58 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2017-12-20 10:17:58 (GMT)
commit776407fe893fd42972c7e3f71423d9d86741d07c (patch)
tree2d2a5781d83709c56d27e5815af2d7a2fc5726c0 /Lib/test
parent19760863623b636a63ccf649107d9504c6465a92 (diff)
downloadcpython-776407fe893fd42972c7e3f71423d9d86741d07c.zip
cpython-776407fe893fd42972c7e3f71423d9d86741d07c.tar.gz
cpython-776407fe893fd42972c7e3f71423d9d86741d07c.tar.bz2
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')
-rw-r--r--Lib/test/test_atexit.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py
index aa56388..3105f6c 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()