[pypy-commit] pypy py3k: help the test_bz2_file tests cleanup after themselves: have

pjenvey noreply at buildbot.pypy.org
Sun May 5 20:55:38 CEST 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r63863:ed097f0bdea7
Date: 2013-05-05 11:46 -0700
http://bitbucket.org/pypy/pypy/changeset/ed097f0bdea7/

Log:	help the test_bz2_file tests cleanup after themselves: have
	enqueue_for_destruction callbacks triggered by leakfinder invoke
	immediately instead of being scheduling for later (possibly never)

diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -178,7 +178,23 @@
     __multicall__.execute()
 
 def pytest_runtest_teardown(__multicall__, item):
-    __multicall__.execute()
+    user_del_action = None
+    if isinstance(item, py.test.collect.Function):
+        appclass = item.getparent(PyPyClassCollector)
+        if appclass is not None and not appclass.obj.runappdirect:
+            user_del_action = appclass.obj.space.user_del_action
+
+    if user_del_action:
+        # if leakfinder triggers leftover __del__s, ensure their
+        # enqueue_for_destruction callbacks are invoked immediately
+        # instead of scheduled for later (potentially never)
+        user_del_action._invoke_immediately = True
+    try:
+        # leakfinder
+        __multicall__.execute()
+    finally:
+        if user_del_action:
+            user_del_action._invoke_immediately = False
 
     if 'pygame' in sys.modules:
         assert option.view, ("should not invoke Pygame "
diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -446,10 +446,14 @@
         self.dying_objects = []
         self.finalizers_lock_count = 0
         self.enabled_at_app_level = True
+        self._invoke_immediately = False
 
     def register_callback(self, w_obj, callback, descrname):
         self.dying_objects.append((w_obj, callback, descrname))
-        self.fire()
+        if not self._invoke_immediately:
+            self.fire()
+        else:
+            self.perform(None, None)
 
     def perform(self, executioncontext, frame):
         if self.finalizers_lock_count > 0:


More information about the pypy-commit mailing list