Python deadlock using subprocess.popen and communicate
clp2 at rebertia.com
Wed Sep 21 23:52:02 EDT 2011
On Wed, Sep 21, 2011 at 8:32 PM, Roy Smith <roy at panix.com> wrote:
> My reading of the docs
> ts) says that Popen.poll() doesn't return a value, it sets the object's
> return code attribute, which you can then interrogate.
Check if child process has terminated. Set **and return**
[Direct quote from the docs; emphasis added]
> More than that, your loop logic looks amazingly complicated for what's
> basically a simple thing. I suggest something along the lines of:
> # assuming process.returncode is initially None
> while process.returncode is None:
> out, err = process.communicate()
> I haven't tested that, but I think (from reading the docs) that's the
> right idea.
There is no point in communicate()-ing multiple times; communicate()
reads until EOF and only returns after subprocess termination!
More information about the Python-list