]> granicus.if.org Git - python/commitdiff
add a contextmanager to disable the gc
authorBenjamin Peterson <benjamin@python.org>
Thu, 14 Jul 2011 17:48:01 +0000 (12:48 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 14 Jul 2011 17:48:01 +0000 (12:48 -0500)
Lib/test/support.py

index ba53ab99793c9b00a4dae62d40d8208f621e5b79..64864dea23f3bf78fbaf313a71e7d2365d731b9c 100644 (file)
@@ -1005,6 +1005,16 @@ def gc_collect():
     gc.collect()
     gc.collect()
 
+@contextlib.contextmanager
+def disable_gc():
+    have_gc = gc.isenabled()
+    gc.disable()
+    try:
+        yield
+    finally:
+        if have_gc:
+            gc.enable()
+
 
 def python_is_optimized():
     """Find if Python was built with optimizations."""