title: Python read from subprocess stdout and stderr separately while preserving order
body: <p>I have a python subprocess that I'm trying to read output and error streams from. Currently I have it working, but I'm only able to read from <code>stderr</code> after I've finished reading from <code>stdout</code>. Here's what it looks like:</p>
  
  <pre><code>process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  stdout_iterator = iter(process.stdout.readline, b"")
  stderr_iterator = iter(process.stderr.readline, b"")
  
  for line in stdout_iterator:
      # Do stuff with line
      print line
  
  for line in stderr_iterator:
      # Do stuff with line
      print line
  </code></pre>
  
  <p>As you can see, the <code>stderr</code> for loop can't start until the <code>stdout</code> loop completes. How can I modify this to be able to read from both in the correct order the lines come in?</p>
  
  <p><strong>To clarify:</strong> I still need to be able to tell whether a line came from <code>stdout</code> or <code>stderr</code> because they will be treated differently in my code.</p>