Python subprocess never exits and keeps giving empty strings in output -


Therefore, I am writing that there is a problem using the subprocess for Python app. To clarify the problem, I wrote a small script that copies my problem very well. Import from __future__ import print_function

  from the importation of sub process selection as SP = sp.Popen (['ls'], Stdout = sp.PIPE, stderr = sp.PIPE, stdin = Sp.PIPE) p.stdin.close () while p.returncode is none or p.stdout.closed or p.stderr.closed: # print ('returncode available_readers = select ([p.stdout, p.stderr], [], [], 2.0) [0] For available_readers in r: print (r.read (1)) # output_display.insert   

Of course, we all know that the Ls Some of the content can be stdout (or stderr ), but the above script is never present.

That you above I can see the last line (comment) in the script, I put the content in a vaccine text component by subpublishing. Therefore, I can not use the .communicate and other blocked calls like I That I need to command to run, I take a long time and I need to show the output (almost) realtime (of course, I need to run it in a different thread while running it, but it's something else) .

So, I do not understand why this script never runs out. It always continues empty strings (after the expected output of the ls command).

Please advise. I am running Python 2.6.6 at Ajaton 2.10. Edit: Here is the version of the script above that works <__future__ import from import_prinction Import subprocess Select from Selection Import as P = sp.Popen (['ls'], stdout = sp.PIPE, stderr = sp.IPIP, stdin = sp.IPIP) p.stdin.close () while p.poll () There is no one: # print (available_readers = select ([p.stdout, p.stderr], [], [], 2.0) [0]: print (r.read (1), end = '') #Output_display.insert (tk.END, r.read (1)) print (p.stdout.read (), end = '') print (p.stderr.read (), end = '') < / Code>

  While p.returncode is none or p.stdout.closed or p.stderr.close:   

while loops any conditions are true, Wanted to check code> returncode (and poll in each iteration)

Comments