summaryrefslogtreecommitdiff
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-12-07 01:28:27 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2014-12-07 01:28:27 +0100
commita8d66b4ff6f2d4115ccd355ab1b3bc8b263bde90 (patch)
tree640f6d1234725e3eecc46d20455bf0c2e492c1fd /Lib/test/test_sys.py
parentc37dfd4a3630d795c87a040ba3fefc960ca87977 (diff)
downloadcpython-a8d66b4ff6f2d4115ccd355ab1b3bc8b263bde90.tar.gz
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.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 9ac105fe38..ec2eaf3bab 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):