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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • I. Myself

    #1

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

    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.Pope n:

    p = Popen(execName, stdout=PIPE)
    while(1):
    line = p.stdout.readli ne() # get next line
    outfile.write(l ine)
    (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


Working...