def _flush_stdout(): # This is needed before using stderr, since it is never buffered if not stdout.isatty(): stdout.flush()