当python finally遇到break和sys.exit
来源:互联网 发布:mac外置光驱读不了光盘 编辑:程序博客网 时间:2024/05/17 08:50
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 Queueimport threadingimport timeimport sysworkQueue = 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 finally遇到break和sys.exit
- python sys.exit()、break、 exit()、quit()、os._exit()、return的区别
- 当return遇到finally
- 当return遇到finally
- 当return遇到finally
- 当return遇到finally
- python-sys.exit(0)
- python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
- python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
- Python程序退出: os._exit()和sys.exit()
- Python os._exit() sys.exit() exit()区别
- Python os._exit() sys.exit() exit()区别
- Python os._exit() sys.exit() exit()区别
- Python os._exit() sys.exit() exit()区别
- python 退出 os._exit(), sys.exit(), exit()
- Python os._exit, sys.exit
- Python 之 os._exit(), sys.exit()
- 利用Merge代替复杂的UPDATE语句
- seo日常工作要旨
- linux 基础学习之二:ext2文件系统研究
- 转载Android开发中的多线程编程技术
- 变量延迟(下)
- 当python finally遇到break和sys.exit
- ant打包入门
- JavaScript replace() 方法
- 每日视界
- 打印自身代码的C语言小程序
- firefox开发必备工具
- set命令
- Javascript跳转页面和打开新窗口等方法
- redis 密码