mirror of https://github.com/mahmoud/boltons.git
adding GCToggler/gcutils
This commit is contained in:
parent
b5c30bab7b
commit
78b2bc6a9b
|
@ -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)
|
Loading…
Reference in New Issue