发布时间:2019-08-27 08:03:24编辑:auto阅读(2773)
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命令 的几
51920
51679
42008
38846
33332
30309
28949
23958
23876
22244
344°
2568°
3241°
2698°
2676°
3407°
2643°
3476°
5706°
5509°