Python: How to read stdout of subprocess in a nonblocking way
<p>I am trying to make a simple python script that starts a subprocess and monitors its standard output. Here is a snippet from the code:</p>

<pre><code>process = subprocess.Popen([path_to_exe, os.path.join(temp_dir,temp_file)], stdout=subprocess.PIPE)
while True:   
    output=process.stdout.readline()
    print "test"
</code></pre>

<p>The problem is that the script hangs on <code>output=process.stdout.readline()</code> and that the line <code>print "test"</code> only executes after the subprocess is terminated.</p>

<p>Is there a way to read standard output and print it without having to wait for the subprocess to terminate?</p>

<p>The subprocess which I am starting is a Windows binary for which I do not have the source code.</p>

<p>I have found several similar questions, but the answers are only applicable on Linux or in case I have the source of the suprocess I am starting.</p>