当python finally遇到break和sys.exit
2011-12-05 15:47
423 查看
except lite.Error, e: print "Error %s:" % e.args[0] sys.exit(1) print '++++++++++++++++++++++' finally: print "---------------"
finally会不会执行?
在google搜:sys.exit finally第一个:
http://stackoverflow.com/questions/7709411/why-finally-block-is-executing-after-calling-sys-exit0-in-except-block
All
sys.exit()does
is raise an exception of type
SystemExit.!
python很聪明的!
另外一种情况在循环中break
import Queue import threading import time import sys workQueue = Queue.Queue(10) for i in range(0,6): workQueue.put(i) def thread_get(): print 'i am starting------' while True: try: req = workQueue.get() break print 'aaaaaaaaa' except Exception,qe: print 'enmpty-----------' break finally: print 'i finally' workQueue.task_done() for i in range(0,5): t = threading.Thread(target=thread_get) t.setDaemon(True) t.start() workQueue.join() print "Exiting Main Thread"
Py官网说的:When a return, break or continue statement
is executed in the try suite
of a try...finally statement,
the finally clause
is also executed ‘on the way out.’ A continue statement
is illegal in the finally clause.
(The reason is a problem with the current implementation — this restriction may be lifted in the future).
经过测试break后退出,造成task_done 死等
第一次测试竟然通过,,细查只正好放了5个数据进Queue!改成6个死锁!
相关文章推荐
- 当python finally遇到break和sys.exit
- python sys.exit()、break、 exit()、quit()、os._exit()、return的区别
- Python os._exit, sys.exit
- python中break continue exit() pass区别
- python sys.exit()函数说明
- python 之 os._exit() sys.exit() 、exit()
- python之 sys.exit() os._exit() exit() quit()的简单使用
- python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
- python 退出 os._exit(), sys.exit(), exit()
- python中的break、continue、exit()、pass全面解析
- Python中exit、return、sys.exit()等使用实例和区别
- 派生表别名 python编码 enca命令 sys.exit(1) 2016.05.26回顾
- Python os._exit() sys.exit() exit()区别
- python程序退出方式[sys.exit() os._exit() os.kill() os.popen(...)]
- python中,exit,return,sys.exit()等的区别与使用方法
- 详解python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
- Python中 os._exit() sys.exit() exit()区别
- python os._exit(0) and sys.exit(0)
- python 中 os._exit(), sys.exit(), exit() 的区别是什么?
- python----sys.exit()