add a contextmanager to disable the gc

This commit is contained in:
Benjamin Peterson 2011-07-14 12:48:01 -05:00
parent c917494528
commit 31f4beb15e
1 changed files with 10 additions and 0 deletions

View 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."""