Asychronous execution *with* return codes?

Justin gehn13 at
Thu Oct 5 18:19:25 CEST 2006

If you're on a POSIX system, you could use the usual fork/exec/wait:

import os
for lstArgs in pileOflstArgs:
    pid = os.fork()
    if not pid:
        os.execv( app, lstArgs )

for i in range(len(pileOflstArgs)):
    pid, status = os.wait()

Of couse, os.wait() will block until a child exits. Look at the docs
for the status code it returns, though, as it's not just the return
value of the process.

On Oct 5, 7:43 am, "utabintarbo" <utabinta... at> wrote:
> MonkeeSage wrote:
> > utabintarbo wrote:
> > > pid = subprocess.Popen([app] + lstArgs).pid
> > Check out the poll() method and the returncode attribute:
> > for the reply.
> If I understand your meaning, I should do something like this (given I
> wish to run an app against several arguments [my use case]):
> for lstArgs in pileOflstArgs:
>     uniqueProcessID = subprocess.Popen([app] + lstArgs)
>     pid =
>     retcode = uniqueProcessID.poll()
>     # increment uniqueProcessID
>     ....
> If so, how do I handle the poll() on long-running processes? Run a
> bunch and then start a check loop? Am I asking too many questions?

More information about the Python-list mailing list