How can I implement a timeout with subprocess.Popen()?

I

I. Myself

I want my Python program to invoke a compiled C program, and capture the
text output.
Here's a fragment from a program that works, using subprocess.Popen:

p = Popen(execName, stdout=PIPE)
while(1):
line = p.stdout.readline() # get next line
outfile.write(line)
(Then I test for a certain unique phrase in line, and then break
if it occurs)

The above works fine as long as the target program runs for a little
while and then stops. But what if it does not stop? It might run
forever, with or without outputting any lines. How can I make this
robust? The keyword might not occur. The target might crash. It might
run forever, with or without text output.

Thanks,

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. If you want to write software,
or articles, or do testing or research for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the 3 digit number)
zenguy at shaw666 dot ca
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top