adding GCToggler/gcutils

This commit is contained in:
Mahmoud Hashemi 2015-03-04 02:26:00 -08:00
parent b5c30bab7b
commit 78b2bc6a9b
1 changed files with 20 additions and 0 deletions

20
boltons/gcutils.py Normal file
View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
import gc
class GCToggler(object):
def __init__(self, postcollect=False):
self.postcollect = postcollect
def __enter__(self):
gc.disable()
def __exit__(self, exc_type, exc_val, exc_tb):
gc.enable()
if self.postcollect:
gc.collect()
toggle_gc = GCToggler()
toggle_gc_postcollect = GCToggler(postcollect=True)