docs: def tee(*popenargs, **kwargs):
      """
      Run a command as if it were piped though tee.
  
      Output generated by the command is displayed in real time to the terminal.  
      It is also captured in strings and returned once the process terminated.  
      This function is very useful for logging output from cluster runs.  Naive 
      approaches like check_output() are vulnerable to crashes (i.e. if a job 
      exceeds its time limit) if they hold all output until the end.  This 
      function echos any output as soon as it's generated, so that the cluster 
      logging system will still work.
      """
  
      import subprocess, select, sys
  
      process = subprocess.Popen(
              stdout=subprocess.PIPE, stderr=subprocess.PIPE,
              *popenargs, **kwargs)
  
      stdout, stderr = '', ''
  
      def read_stream(input_callback, output_stream):   # (no fold)
          read = input_callback()
          output_stream.write(read)
          output_stream.flush()
          return read
  
      while process.poll() is None:
          watch = process.stdout.fileno(), process.stderr.fileno()
          ready = select.select(watch, [], [])[0]
  
          for fd in ready:
              if fd == process.stdout.fileno():
                  stdout += read_stream(process.stdout.readline, sys.stdout)
              if fd == process.stderr.fileno():
                  stderr += read_stream(process.stderr.readline, sys.stderr)
  
      stdout += read_stream(process.stdout.read, sys.stdout)
      stderr += read_stream(process.stderr.read, sys.stderr)
  
      return stdout, stderr