How to get a raised exception from other thread

themightydoyle at gmail.com themightydoyle at gmail.com
Sat Oct 15 23:54:33 EDT 2005


Here's a dumbed down version of what i'm doing:

import time
import threading

class threader(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        pass

    def run(self):
        try:
            while 1:
                time.sleep(5)
        except SystemExit:
            print "Got Exit Message in thread"

    def killMe(self):
        raise SystemExit



thread1 = threader()
thread2 = threader()

thread1.start()
thread2.start()

time.sleep(5)

try:
    print "Killing thread 1"
    thread1.killMe()
    print "killing thread 2"
    thread2.killMe()
except SystemExit:
    print "Got exceptin in main thread"



The exception is not propogated to the threads I spawned, but instead
comes back in the main thread.




More information about the Python-list mailing list