code: def do_write(self):
          
          while True:
              try:
                  written = 0
  
                  if hasattr(self.fd, 'send'):
                      written = self.fd.send(self.buffer)
                  else:
                      written = os.write(self.fd.fileno(), self.buffer)
  
                  self.buffer = self.buffer[written:]
  
                  # try to close after writes if a close was requested
                  if self.close_requested and len(self.buffer) == 0:
                      self.close()
  
                  return written
              except EnvironmentError as e:
                  if e.errno not in Stream.ERRNO_RECOVERABLE:
                      raise e
docs: Flushes as much pending data from the internal write buffer as possible.