发布时间:2019-08-27 08:03:24编辑:auto阅读(2472)
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命令 的几
49395
48597
39284
36373
30779
27594
26586
21406
21269
19615
259°
503°
485°
582°
945°
654°
1334°
1582°
1253°
1232°