title: A non-blocking read on a subprocess.PIPE in Python
body: <p>I'm using the <a href="http://docs.python.org/library/subprocess.html" rel="noreferrer">subprocess module</a> to start a subprocess and connect to its output stream (standard output). I want to be able to execute non-blocking reads on its standard output. Is there a way to make .readline non-blocking or to check if there is data on the stream before I invoke <code>.readline</code>? I'd like this to be portable or at least work under Windows and Linux.</p>
  <p>Here is how I do it for now (it's blocking on the <code>.readline</code> if no data is available):</p>
  <pre><code>p = subprocess.Popen('myprogram.exe', stdout = subprocess.PIPE)
  output_str = p.stdout.readline()
  </code></pre>