def silence(filter_=lambda line: True, file_=stdout):
    """
    Prevent lines matching `filter_` ending up on `file_` (defaults to stdout)
    """
    if not filter_:
        yield
        return
    
    saved_stdout = dup(file_.fileno())
    stdout_file = PyFile_AsFile(file_)
    
    with nested(fdopen(saved_stdout, "w"), fifo()) as (real_stdout, filename):
        with threaded_file_reader(filename, filter_, real_stdout):
            # Redirect stdout to pipe
            freopen(filename, "w", stdout_file)
            try:
                yield
            finally:
                # Redirect stdout back to it's original place
                freopen("/dev/fd/%i" % saved_stdout, "w", stdout_file)

    Prevent lines matching `filter_` ending up on `file_` (defaults to stdout)
    
recipes/Python/577083_POSIX_context_manager_temporarily_silence_or/recipe-577083.py