Non-blocking read on a stream in python.
- by Mathieu Pagé
Hi,
I'm using the subprocess module to start a subprocess and connect to it's output stream (stdout). I want to be able to execute non-blocking reads on its stdout. Is there a way to make .readline non-bloking or to check if there is data on the stream before I invoke .readline? I'd like this to be portable or at least work under Windows and Linux.
here is how I do it for now (It's blocking on the .readline if no data is avaible):
p = subprocess.Popen('myprogram.exe', stdout = subprocess.PIPE)
str = p.stdout.readline()
Thanks for your help.