Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88291:763c24bd5dca
Date: 2016-11-10 10:55 +0100
http://bitbucket.org/pypy/pypy/changeset/763c24bd5dca/

Log:    sys.is_finalizing()

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -443,6 +443,7 @@
         self.wait_for_thread_shutdown()
         w_atexit = self.getbuiltinmodule('atexit')
         self.call_method(w_atexit, '_run_exitfuncs')
+        self.sys.finalizing = True
         self.sys.flush_std_files(self)
         from pypy.interpreter.module import Module
         for w_mod in self.builtin_modules.values():
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -27,6 +27,7 @@
         self.filesystemencoding = None
         self.debug = True
         self.track_resources = False
+        self.finalizing = False
         self.dlopenflags = rdynload._dlopen_default_mode()
 
     interpleveldefs = {
@@ -94,6 +95,8 @@
 
         'get_coroutine_wrapper' : 'vm.get_coroutine_wrapper',
         'set_coroutine_wrapper' : 'vm.set_coroutine_wrapper',
+
+        'is_finalizing'         : 'vm.is_finalizing',
         }
 
     if sys.platform == 'win32':
diff --git a/pypy/module/sys/test/test_sysmodule.py 
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -668,6 +668,12 @@
         # be changed.
         assert sys.float_repr_style == "short"
 
+    def test_is_finalizing(self):
+        import sys
+        assert not sys.is_finalizing()
+        # xxx should also test when it is True, but maybe not worth the effort
+
+
 class AppTestSysSettracePortedFromCpython(object):
     def test_sys_settrace(self):
         import sys
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -308,3 +308,6 @@
         ec.w_coroutine_wrapper_fn = w_wrapper
     else:
         raise oefmt(space.w_TypeError, "callable expected, got %T", w_wrapper)
+
+def is_finalizing(space):
+    return space.wrap(space.sys.finalizing)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to