code: def _write_flush(self, fd, payload=None):
      
      try:
        if payload:
          fd.write(ensure_binary(payload))
        fd.flush()
      except (IOError, OSError) as e:
        # If a `Broken Pipe` is encountered during a stdio fd write, we're headless - bail.
        if e.errno == errno.EPIPE and self._exit_on_broken_pipe:
          sys.exit()
        # Otherwise, re-raise.
        raise
docs: Write a payload to a given fd (if provided) and flush the fd.