subprocess solved all my problems

  • Thread starter =?ISO-8859-2?Q?Jacek_Pop=B3awski?=
  • Start date
?

=?ISO-8859-2?Q?Jacek_Pop=B3awski?=

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()
 
P

Peter Hansen

Jacek said:
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....*+jacek+popen+thread&rnum=2#ebca44930a016f74
)

-Peter
 
D

Do Re Mi chel La Si Do

Hi !

Thank you for this interesting message.

@-salutations

Michel Claveau
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top