How to get a raised exception from other thread

dcrespo dcrespo at gmail.com
Fri Oct 14 23:45:20 CEST 2005


Hi all,

How can I get a raised exception from other thread that is in an
imported module?

For example:

---------------
programA.py
---------------

import programB

thread = programB.MakeThread()
thread.start()

---------------
programB.py
---------------
import threading, time

class SomeException(Exception):
    pass

class MakeThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        i = 0
        while 1:
            print i
            i += 1
            time.sleep(1) #wait a second to continue
            if i>10:
                raise SomeException()


Thanks

Daniel




More information about the Python-list mailing list