Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Asychronous execution *with* return codes?

Reply
Thread Tools

Asychronous execution *with* return codes?

 
 
utabintarbo
Guest
Posts: n/a
 
      10-05-2006
I hope I have not overlooked a solution already posted, but I seem to
be unable to suss out a way to achieve both multiple console-less
executions of a given (console) application and gathering the return
code from the application.

What I have found:
<code>
import subprocess

# gives back return code, but does not run asynchronously
retcode = subprocess.call([app, lstArgs])
retcode = subprocess.Popen([app] + lstArgs).wait()
# runs the app async, but only returns the pid (no return code)
pid = subprocess.Popen([app] + lstArgs).pid
</code>

Is there some magic elixir which will get me both?

TIA

 
Reply With Quote
 
 
 
 
MonkeeSage
Guest
Posts: n/a
 
      10-05-2006
utabintarbo wrote:
> pid = subprocess.Popen([app] + lstArgs).pid


Check out the poll() method and the returncode attribute:
http://docs.python.org/lib/node533.html

Regards,
Jordan

 
Reply With Quote
 
 
 
 
utabintarbo
Guest
Posts: n/a
 
      10-05-2006

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.html
>


Thanks 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?

 
Reply With Quote
 
Justin
Guest
Posts: n/a
 
      10-05-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" <(E-Mail Removed)> 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?


 
Reply With Quote
 
utabintarbo
Guest
Posts: n/a
 
      10-05-2006

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

Sorry. Win32. We are only allowed spoons - no sharp objects.

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      10-05-2006
At Thursday 5/10/2006 09:33, utabintarbo wrote:

># gives back return code, but does not run asynchronously
>retcode = subprocess.call([app, lstArgs])
>retcode = subprocess.Popen([app] + lstArgs).wait()
># runs the app async, but only returns the pid (no return code)
>pid = subprocess.Popen([app] + lstArgs).pid
></code>
>
>Is there some magic elixir which will get me both?


Use the async way, and then, os.waitpid()



Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      10-09-2006
In message <(E-Mail Removed). com>,
utabintarbo wrote:

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

> Sorry. Win32. We are only allowed spoons - no sharp objects.


How about installing Cygwin, then, and running under that?
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      10-09-2006
utabintarbo wrote:

> If so, how do I handle the poll() on long-running processes? Run a
> bunch and then start a check loop?


or use a thread to keep track of each external process.

</F>


 
Reply With Quote
 
utabintarbo
Guest
Posts: n/a
 
      10-11-2006

Fredrik Lundh wrote:
> utabintarbo wrote:
>
> > If so, how do I handle the poll() on long-running processes? Run a
> > bunch and then start a check loop?

>
> or use a thread to keep track of each external process.
>
> </F>


This sounds most promising. Might you have a code snippet (or link to
same) illustrating this?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asychronous server socket problem cmrhema ASP .Net 0 08-07-2008 12:27 PM
how to use asychronous calls SenthilVel ASP .Net 0 05-15-2006 02:10 PM
Problem with Asychronous Web Service Callback Frank Mamone ASP .Net 2 09-14-2004 01:39 PM
asychronous sram read and write yali VHDL 2 08-31-2004 05:11 AM
multiple asychronous resets Ruth VHDL 1 06-26-2003 06:01 PM



Advertisments