1 import sys
2 import threading
3 import Queue
4
6 """A thread that can throw an exception to the joining thread."""
7
9 """
10 @param status_queue: a queue that will hold an exception if it is
11 thrown by the thread
12 @type status_queue: L{Queue.Queue} or C{None}
13 """
14 threading.Thread.__init__(self)
15 self.__status_queue = status_queue
16 if self.__status_queue is None:
17 self.__status_queue = Queue.Queue()
18
20 """This method should be overriden."""
21 raise NotImplementedError
22
24 """DO NOT override this method."""
25 try:
26 self.run_with_exception()
27 except Exception:
28 self.__status_queue.put(sys.exc_info())
29 self.__status_queue.put(None)
30
32 return self.__status_queue.get()
33
35 ex_info = self.wait_for_exc_info()
36 if ex_info is None:
37 return
38 else:
39 raise ex_info[1]
40