import gc gc.disable() # code ... gc.enable()