diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-07-14 17:48:01 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-07-14 17:48:01 (GMT) |
commit | 31f4beb15e959e818947db3297ac639bc2afc067 (patch) | |
tree | 3633e894c665049abd960ea17189069f77e389a0 /Lib | |
parent | c917494528b3e116d4d17df52daea74f112e2b68 (diff) | |
download | cpython-31f4beb15e959e818947db3297ac639bc2afc067.zip cpython-31f4beb15e959e818947db3297ac639bc2afc067.tar.gz cpython-31f4beb15e959e818947db3297ac639bc2afc067.tar.bz2 |
add a contextmanager to disable the gc
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/support.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index ba53ab9..64864de 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -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.""" |