Python timeout example.
import signal, os, subprocess
def alarm_handler(signum, frame):
# start timer, currently set to go off in 3 seconds
signal.alarm(3) # 3 seconds
# perform some tasks here, for this example I use a sleep of 20 seconds which will get interrupted.
time.sleep(20) # wait 20 seconds, note this time must be larger than the value of start timer.
signal.alarm(0) # reset the alarm
print "Oops, taking too long!"
This entry was posted in Uncategorized
. Bookmark the permalink