← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #156909]: MAC : Python: Issues with exit code when running Sikuli script with subprocess.Popen()

 

Question #156909 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/156909

RaiMan posted a new comment:
One more thing: (subprocess.PIPE)

I just scanned the Python docs again:

You use "stdout=subprocess.PIPE, stderr=subprocess.PIPE". In this case
it is recommended to use communicate() instead of wait, since the PIPES
might stop, if not emptied.

from the docs of subprocess.wait()
WARNING This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that.

So the usage in this case would be:
p = subprocess.Popen(<what ever needed>, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(sout, serr) = p.communicate()
for line in p.sout: # if needed
   print line
for line in p.serr: # if needed
   print line

There is another very informative and readable doc on this matter: 
http://jimmyg.org/blog/2009/working-with-python-subprocess.html

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.