mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-31901: atexit callbacks should be run at subinterpreter shutdown (#4611)
Change atexit behavior and PEP-489 multiphase init support.
This commit is contained in:
parent
1976086362
commit
776407fe89
10 changed files with 91 additions and 46 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue