By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

subprocess solved all my problems

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
Hi !

Thank you for this interesting message.

@-salutations

Michel Claveau

Sep 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.