Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r88894:407896dd979f
Date: 2016-12-06 11:00 +0100
http://bitbucket.org/pypy/pypy/changeset/407896dd979f/

Log:    Fix 3cffc7191d14 for -A

diff --git a/pypy/interpreter/executioncontext.py 
b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -547,6 +547,8 @@
 
     @jit.dont_look_inside
     def _run_finalizers(self):
+        # called by perform() when we have to "perform" this action,
+        # and also directly at the end of gc.collect).
         while True:
             w_obj = self.space.finalizer_queue.next_dead()
             if w_obj is None:
diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -23,9 +23,18 @@
     # specifically rely on that.  This is similar to how, in CPython, an
     # explicit gc.collect() will invoke finalizers from cycles and fully
     # ignore the gc.disable() mode.
-    if not space.user_del_action.enabled_at_app_level:
+    temp_reenable = not space.user_del_action.enabled_at_app_level
+    if temp_reenable:
         enable_finalizers(space)
-        disable_finalizers(space)
+    try:
+        # fetch the pending finalizers from the queue, where they are
+        # likely to have been added by rgc.collect() above, and actually
+        # run them now.  This forces them to run before this function
+        # returns, and also always in the enable_finalizers() mode.
+        space.user_del_action._run_finalizers()
+    finally:
+        if temp_reenable:
+            disable_finalizers(space)
 
     return space.wrap(0)
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to