发布时间:2019-08-27 08:03:24编辑:auto阅读(2573)
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命令 的几
50477
49773
40364
37393
31814
28670
27606
22391
22388
20699
457°
1075°
874°
811°
1054°
930°
1547°
2888°
2586°
1985°