发布时间:2019-08-27 08:03:24编辑:auto阅读(3090)
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命令 的几
53728
40566
34988
30712
25579
25354
23793
19263
15387
14882
1428°
1320°
1420°
1450°
1465°
1646°
1594°
1507°
1605°
1560°