Author: Antonio Cuni <[email protected]>
Branch: gc-disable
Changeset: r94711:5a7307d2116c
Date: 2018-05-29 16:25 +0200
http://bitbucket.org/pypy/pypy/changeset/5a7307d2116c/
Log: add a method to manually run a single gc-collect-step
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -770,6 +770,22 @@
self.minor_and_major_collection()
self.rrc_invoke_callback()
+ def collect_step(self):
+ """
+ Do a single major collection step. Return True when the major
collection
+ is completed.
+
+ This is meant to be used together with gc.disable(), to have a
+ fine-grained control on when the GC runs.
+ """
+ in_progress = self.gc_state != STATE_SCANNING
+ self._minor_collection()
+ self.major_collection_step()
+ self.rrc_invoke_callback()
+ # if we were in the middle of a collection and we are back to
+ # STATE_SCANNING, it means we have just finished one
+ done = in_progress and self.gc_state == STATE_SCANNING
+ return done
def minor_collection_with_major_progress(self, extrasize=0,
force_enabled=False):
diff --git a/rpython/memory/gc/test/test_direct.py
b/rpython/memory/gc/test/test_direct.py
--- a/rpython/memory/gc/test/test_direct.py
+++ b/rpython/memory/gc/test/test_direct.py
@@ -821,3 +821,16 @@
assert sorted(debuglog.summary()) == ['gc-collect-step', 'gc-minor']
# s is freed
py.test.raises(RuntimeError, 's.x')
+
+ def test_collect_step(self, debuglog):
+ n = 0
+ while True:
+ debuglog.reset()
+ done = self.gc.collect_step()
+ summary = debuglog.summary()
+ assert summary == {'gc-minor': 1, 'gc-collect-step': 1}
+ if done:
+ break
+ n += 1
+ if n == 100:
+ assert False, 'this looks like an endless loop'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit