def flush ( ) : try : sys . stdout . flush ( ) sys . stderr . flush ( ) except ( AttributeError , ValueError , IOError ) : pass # unsupported try : libc . fflush ( None ) except ( AttributeError , ValueError , IOError ) : pass
python flush all buffer
Try to flush all stdio buffers both from python and from C .
def flush():
    """Try to flush all stdio buffers, both from python and from C."""
    try:
        sys.stdout.flush()
        sys.stderr.flush()
    except (AttributeError, ValueError, IOError):
        pass  # unsupported
    try:
        libc.fflush(None)
    except (AttributeError, ValueError, IOError):
        pass