code: def _get_stdout_stderr_streams(self):
          
          if six.PY2 or not hasattr(sys.stdout, "buffer"):
              if hasattr(sys.stdout, "fileno") and sys.stdout.isatty():
                  try:
                      stdout = os.fdopen(sys.stdout.fileno(), "w+", 0)
                      stderr = os.fdopen(sys.stderr.fileno(), "w+", 0)
                  # OSError [Errno 22] Invalid argument wandb
                  except OSError:
                      stdout = sys.stdout
                      stderr = sys.stderr
              else:
                  stdout = sys.stdout
                  stderr = sys.stderr
          else:  # we write binary so grab the raw I/O objects in python 3
              try:
                  stdout = sys.stdout.buffer.raw
                  stderr = sys.stderr.buffer.raw
              except AttributeError:
                  # The testing environment and potentially others may have screwed with their
                  # io so we fallback to raw stdout / err
                  stdout = sys.stdout.buffer
                  stderr = sys.stderr.buffer
  
          output_log_path = os.path.join(self._run.dir, OUTPUT_FNAME)
          self._output_log = WriteSerializingFile(open(output_log_path, 'wb'))
  
          stdout_streams = [stdout, self._output_log]
          stderr_streams = [stderr, self._output_log]
  
          if self._cloud:
              # Tee stdout/stderr into our TextOutputStream, which will push lines to the cloud.
              fs_api = self._api.get_file_stream_api()
              self._stdout_stream = streaming_log.TextStreamPusher(
                  fs_api, OUTPUT_FNAME, prepend_timestamp=True)
              self._stderr_stream = streaming_log.TextStreamPusher(
                  fs_api, OUTPUT_FNAME, line_prepend='ERROR',
                  prepend_timestamp=True)
  
              stdout_streams.append(self._stdout_stream)
              stderr_streams.append(self._stderr_stream)
  
          return stdout_streams, stderr_streams
docs: Sets up STDOUT and STDERR streams. Only call this once.