Asychronous execution *with* return codes?

Justin gehn13 at gmail.com
Thu Oct 5 12:19:25 EDT 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 gmail.com> wrote:
> MonkeeSage wrote:
> > utabintarbo wrote:
> > > pid = subprocess.Popen([app] + lstArgs).pid
>
> > Check out the poll() method and the returncode attribute:
> >http://docs.python.org/lib/node533.htmlThanks 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 = uniqueProcessID.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