def subprocess_timeout(sec):
import signal
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
@subprocess_timeout(5)
def test_timeout():
while true:
print "11111"
if__name__="__main":
test_timeout()