In my Python script I make an external call using subprocess.Popen(). If the call hasn’t returned within x seconds I need to send an email indicating that something is wrong. How can I put a time limit on the execution of the external call? Note that I am not interested in terminating the call, just detecting that it takes too long.
Thanks in advance!
That’s what the subprocess object’s
pollis for. See http://docs.python.org/library/subprocess.html#subprocess.Popen.pollYou can use
time.sleep()to wait for the timeout interval. Thenpollthe subprocess object to see if it’s done.If it’s done, that’s good.
If it’s not done, your app sends an email.