473,387 Members | 1,550 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,387 software developers and data experts.

subprocess solved all my problems

In the last week I was working to create script which will read command
from socket, call it, return result, stdout, stderr and kill it after
timeout.
After playing with threads, processes, spawns and popens I found
subprocess module.

To call command I use following construction:

finish=time.time()+self.timeout
self.p=subprocess.Popen(self.command,shell=True,
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while (self.p.poll()==None) and (time.time()<finish):
pass #FIXME more CPU friendly
result=self.p.poll();
if (result==None):
print "kill!"
os.kill(self.p.pid,9)
return result

then to get its stdout:

self.p.stdout.read()
Sep 9 '05 #1
2 3593
Jacek Popławski wrote:
In the last week I was working to create script which will read command
from socket, call it, return result, stdout, stderr and kill it after
timeout.
After playing with threads, processes, spawns and popens I found
subprocess module.

[snip rest of answer]

While in general it's greatly appreciated when people post followups
showing the answer to their problems, by not posting this in response to
the original thread (and by changing the subject line) you are vastly
reducing the value of your post. It's much less likely someone
searching the archives will ever discover that you did find a solution
than if you were to go back and repost it to the original thread.

(If you can't find it in your news server, you could probably use Google
Groups. I *think* this was the thread you were referring to, but you
should confirm for yourself:
http://groups.google.com/group/comp....ca44930a016f74
)

-Peter
Sep 9 '05 #2
Hi !

Thank you for this interesting message.

@-salutations

Michel Claveau

Sep 9 '05 #3

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

Similar topics

5
by: Michele Simionato | last post by:
I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I wonder why a "kill" method is missing. I am just adding it via subclassing, class Popen(subprocess.Popen): def...
4
by: Pekka Niiranen | last post by:
Hi, I am running Python script in W2K or in WinXP. The script is started from DOS prompt and writes text file to disk with codecs.open() in UTF8. The problem is: When script writes the file...
3
by: rh0dium | last post by:
Hi all, Here I was happily coming to working thinking - OK I need to create a wrapper for a tool (UNIX) which does nothing but lauch the end tool and send a sql instert letting the db know the...
13
by: bayer.justin | last post by:
Hi, I am trying to communicate with a subprocess via the subprocess module. Consider the following example: <subprocess.Popen object at 0x729f0> Here hey is immediately print to stdout of...
3
by: Michael Williams | last post by:
Hi All, I've recently seen the "subprocess" module and am rather confused by it's requirements. Is it not possible to execute an entire string without having to break them up into a list of...
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
9
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
2
by: dudeja.rajat | last post by:
On Mon, Sep 8, 2008 at 11:50 AM, <dudeja.rajat@gmail.comwrote: Ok, I re-phrase my question: there is a batch file that executes a exe file. The batch just works if run from command prompt and...
1
by: yogamatt1970 | last post by:
I have some code which runs on a number of different machines, however I see problems on one particular Solaris box. When I call Popen.wait(), the following exception is raised: .. . . File...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.