473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Asychronous execution *with* return codes?

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

Oct 5 '06 #1
8 1557
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

Oct 5 '06 #2

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?

Oct 5 '06 #3
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...@gmail.comwrote:
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?
Oct 5 '06 #4

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. :-P

Oct 5 '06 #5
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

Oct 5 '06 #6
In message <11**********************@e3g2000cwe.googlegroups. 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. :-P
How about installing Cygwin, then, and running under that?
Oct 9 '06 #7
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>
Oct 9 '06 #8

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?

Oct 11 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: satish | last post by:
Hello all, I have a shared object executable viz. *cable* which I execute as follows : $ ansyscust71 -custom cable -p ANSYSRF **ansyscust71 is a shell script and is a part of a software...
1
by: Raquel | last post by:
This is a stored procedure that resides on Mainframe and gets executed on the client by connecting to the mainframe through DB2 connect. It was executing fine till yesterday when I executed a table...
3
by: c# beginner | last post by:
we are trying to standardize return codes across our .NET applications (that are soon to be developed.) What is the best practice for standardizing return codes? I know of only the following...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
4
by: archana | last post by:
Hi all, I am having one confusion regarding invoking web method of web service asychronously through windows applicaiton. What i am doing is i am having one long runing web method whose one...
1
by: SenthilVel | last post by:
Hi all i have a requirement in my application where in need to call a web service: 1. My client calls my webservice . 2. when i receive a call from my web servcie i need to notify my client...
7
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain...
2
by: William Johnston | last post by:
Hello, I need to perform synchronous calls to a DllImport function that is asychronous. (The Dllmport function returns immediately.) So far I have a timer that waits inside a ThreadPool queue....
0
by: spearlselvam | last post by:
Hi all, I have created a chat appln using asychronous socket.. can anyone say the diff of using the below code snippet 1. SetControlProperty(conStatus, "Text", receivedData); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.