capture exception raised by child thread.

Joe Wong joewong at mango.cc
Thu May 13 23:32:36 EDT 2004


Hi,

 I have a class that created a child thread for processing, this thread might raise an exception under some condition. On the main program that create an object of this case, I put a try/except block trying to capture the exception but failed. Am I doing anything wrong here?

here is the stripped version of my code:

class A:
    def __init__(self):
        self.thread = threading.Thread(None, self.MyThread)
        self.thread.setDaemon(1)
        self.thread.start()

    def MyThread(self):
        while 1:
            # do something. if error:

            if error:
                raise exception

in my Main  program:

main()
    a = A()
    while 1:
        try:
            # do something..
        except exception, e:
            # I should capture the exception from A, but not..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040514/44de7f09/attachment.html>


More information about the Python-list mailing list