I have a python script that calls a binary. I want to make sure that if the binary fails (with a 2 min timeout) it kills the process. Currently I'm unable to do that as I only kill the function but the binary is still running. Please help
#!/usr/bin/python26
from optparse import OptionParser
import nagios
import re
import subprocess
import commands
import signal
import time
...
...
...
class Alarm(Exception):
pass
def alarm_handler(signum, frame):
raise Alarm
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(120) # 2 minutes
def check_blaze_login(serviceName, rdir, masterAcct, persona, passwd):
cmd = TESTHARNESS_PATH + ' -s ' + serviceName + ' -r ' + rdir + \
' -m ' + masterAcct + ' -p ' + persona + ' -P ' + passwd
try:
status, info, prof = check_blaze_login(options.serviceName, options.rdir, options.masterAcct,
options.persona, options.passwd)
signal.alarm(0)
except Alarm:
status = nagios.STATUS_WARN
info = 'testharness timed out!'
prof = ''