code: async def stdout_writer():
      
      if sys.stdout.seekable():
          # it’s a file
          return sys.stdout.buffer.raw
  
      if os.isatty(sys.stdin.fileno()):
          # it’s a tty, use fd 0
          fd_to_use = 0
      else:
          fd_to_use = 1
  
      twrite, pwrite = await loop.connect_write_pipe(
          asyncio.streams.FlowControlMixin,
          os.fdopen(fd_to_use, "wb"),
      )
  
      swrite = asyncio.StreamWriter(
          twrite,
          pwrite,
          None,
          loop,
      )
  
      return swrite
docs: This is a bit complex, as stdout can be a pipe or a file.
  
      If it is a file, we cannot use
      :meth:`asycnio.BaseEventLoop.connect_write_pipe`.