import time
import signal
def timeout(sec):
print sec
def wrapper1(func):
def wrapper(*args, *kw):
def handler(signum, frame):
raise AssertionError
try:
signal.signal(signal.SIGALRM, handler)
signal.alarm(sec)
return func(args)
except AssertionError:
print "call {} timeout".format(func)
return wrapper
return wrapper1
@timeout(5)
def test():
while(True):
print "111111"
time.sleep(1)
if name == "main":
test()