Public Member Functions | |
def | raiseExc |
Private Member Functions | |
def | _get_my_tid |
Private Attributes | |
_thread_id |
A thread class that supports raising exception in the thread from another thread.
Definition at line 15 of file thread_exception.py.
def thread_exception.ThreadWithExc._get_my_tid | ( | self | ) | [private] |
determines this (self's) thread id CAREFUL : this function is executed in the context of the caller thread, to get the identity of the thread represented by this instance.
Definition at line 19 of file thread_exception.py.
def thread_exception.ThreadWithExc.raiseExc | ( | self, | |
exctype | |||
) |
Raises the given exception type in the context of this thread. If the thread is busy in a system call (time.sleep(), socket.accept(), ...), the exception is simply ignored. If you are sure that your exception should terminate the thread, one way to ensure that it works is: t = ThreadWithExc( ... ) ... t.raiseExc( SomeException ) while t.isAlive(): time.sleep( 0.1 ) t.raiseExc( SomeException ) If the exception is to be caught by the thread, you need a way to check that your thread has caught it. CAREFUL : this function is executed in the context of the caller thread, to raise an excpetion in the context of the thread represented by this instance.
Definition at line 43 of file thread_exception.py.
Definition at line 24 of file thread_exception.py.