import timetry: time.sleep(10)finally: print "clean up"clean upTraceback (most recent call last): File "<stdin>", line 2, in <module>KeyboardInterrupt
如果需要捕获其他 *** 作系统级别的中断,请查看信号模块:
http://docs.python.org/library/signal.html
信号示例from signal import *import sys, timedef clean(*args): print "clean me" sys.exit(0)for sig in (SIGABRT, SIGBREAK, SIGILL, SIGINT, SIGSEGV, SIGTERM): signal(sig, clean)time.sleep(10)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)