@contextlib.contextmanager<EOL>def _silence():
old_stdout = sys.stdout<EOL>old_stderr = sys.stderr<EOL>sys.stdout = _DummyFile()<EOL>sys.stderr = _DummyFile()<EOL>exception_occurred = False<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>except:<EOL><INDENT>exception_occurred = True<EOL>sys.stdout = old_stdout<EOL>sys.stderr = old_stderr<EOL>raise<EOL><DEDENT>if not exception_occurred:<EOL><INDENT>sys.stdout = old_stdout<EOL>sys.stderr = old_stderr<EOL><DEDENT>
A context manager that silences sys.stdout and sys.stderr.