diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-12-07 00:28:27 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-12-07 00:28:27 (GMT) |
commit | 5db1bb81ff88c90364cfcf458bae8115126411d8 (patch) | |
tree | 334a5d67f565b3a103f068a82147b6bede9e1b20 /Lib/test/test_sys.py | |
parent | b9859daeeb8ad767d2b2cc56f72736810114dd49 (diff) | |
download | cpython-5db1bb81ff88c90364cfcf458bae8115126411d8.zip cpython-5db1bb81ff88c90364cfcf458bae8115126411d8.tar.gz cpython-5db1bb81ff88c90364cfcf458bae8115126411d8.tar.bz2 |
Issue #22696: Add function :func:`sys.is_finalizing` to know about interpreter shutdown.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 9ac105f..ec2eaf3 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -744,6 +744,27 @@ class SysModuleTest(unittest.TestCase): c = sys.getallocatedblocks() self.assertIn(c, range(b - 50, b + 50)) + def test_is_finalizing(self): + self.assertIs(sys.is_finalizing(), False) + # Don't use the atexit module because _Py_Finalizing is only set + # after calling atexit callbacks + code = """if 1: + import sys + + class AtExit: + is_finalizing = sys.is_finalizing + print = print + + def __del__(self): + self.print(self.is_finalizing(), flush=True) + + # Keep a reference in the __main__ module namespace, so the + # AtExit destructor will be called at Python exit + ref = AtExit() + """ + rc, stdout, stderr = assert_python_ok('-c', code) + self.assertEqual(stdout.rstrip(), b'True') + @test.support.cpython_only class SizeofTest(unittest.TestCase): |