import time
import signal
def test():
while(True):
print "111111"
time.sleep(1)
def exec_timeout(func, timeout):
def handler(signum, frame):
raise AssertionError
try:
signal.signal(signal.SIGALRM, handler)
signal.alarm(timeout)
test()
signal.alarm(0)
except AssertionError:
print "timeout"
if name == "main":
exec_timeout(test, 5)