@contextlib.contextmanager
def _silence():
 old_stdout = sys.stdout
 old_stderr = sys.stderr
 sys.stdout = _DummyFile()
 sys.stderr = _DummyFile()
 exception_occurred = False
 try:
  (yield)
 except:
  exception_occurred = True
  sys.stdout = old_stdout
  sys.stderr = old_stderr
  raise
 if (not exception_occurred):
  sys.stdout = old_stdout
  sys.stderr = old_stderr

@ contextlib . contextmanager def _silence ( ) : old_stdout = sys . stdout old_stderr = sys . stderr sys . stdout = _DummyFile ( ) sys . stderr = _DummyFile ( ) exception_occurred = False try : ( yield ) except : exception_occurred = True sys . stdout = old_stdout sys . stderr = old_stderr raise if ( not exception_occurred ) : sys . stdout = old_stdout sys . stderr = old_stderr
a context manager that silences sys .