发布时间:2019-08-27 08:03:24编辑:auto阅读(2424)
import time
import signal
def test(i):
time.sleep(i % 4)
print "%d within time" % (i)
return i
if __name__ == '__main__':
def handler(signum, frame):
raise AssertionError
for i in range(1, 10):
try:
signal.signal(signal.SIGALRM, handler)
signal.alarm(3)
test(i)
except AssertionError:
print "%d timeout" % (i)
finally:
signal.alarm(0)
signal.signal(signal.SIGALRM, signal.SIG_DFL)
1 within time2 within time3 timeout4 within time5 within time6 within time7 timeout8 within time9 within time博客原文:http://blog.sina.com.cn/s/blog_63041bb80102uy5o.html
上一篇: 使用Sublime Text搭建pyth
下一篇: python 执行 shell命令 的几
48866
47934
38709
35858
30285
27039
26071
20903
20698
19067
502°
595°
604°
609°
587°
572°
637°
711°
830°
928°