2006年03月16日 星期四 09:15
python,您好!
我做的一个程序中,会开几个子线程,现在遇到的问题是,如果子线程中发生异常,则线程没有任何信息显示,就退出了。如何才能让子线程中发生的异常信息,能象在主线程里那样,显示在控制台中呢?
谢谢。
致
礼!
cry
zyqmail at tom.com
2006年03月16日 星期四 09:25
简单试了一下,会有异常信息啊,不知道你的程序是怎么样的
import threading
import time
class Demo(threading.Thread):
def __init__(self, id, **kwds):
threading.Thread.__init__(self, **kwds)
self.timer = 0
def run(self):
while True:
print self.timer
self.timer += 1
time.sleep(2)
if self.timer == 5:
raise ValueError, 'hahahahahahah'
if __name__ == '__main__':
demo1 = Demo(1)
demo1.start()
while True:
print 'hello'
time.sleep(2)
输出为:
1
hello
2
hello
3
hello
4
hello
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python24\lib\threading.py", line 442, in __bootstrap
self.run()
File "demo.py", line 18, in run
raise ValueError, 'hahahahahahah'
ValueError: hahahahahahah
hello
hello
hello
hello
hello
hello
hello
On 3/16/06, cry <zyqmail at tom.com> wrote:
>
> python,您好!
>
>
> 我做的一个程序中,会开几个子线程,现在遇到的问题是,如果子线程中发生异常,则线程没有任何信息显示,就退出了。如何才能让子线程中发生的异常信息,能象在主线程里那样,显示在控制台中呢?
>
> 谢谢。
>
> 致
> 礼!
>
> cry
> zyqmail at tom.com
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
--
Robert
Python源码剖析――http://blog.donews.com/lemur/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060316/60c7288e/attachment.html
Zeuux © 2025
京ICP备05028076号