Part of bzrlib.cethread View In Hierarchy
Known subclasses: bzrlib.tests.test_server.TestThread
If an exception occurs during the thread execution, it's caught and re-raised when the thread is joined().
|Method||set_sync_event||Set the sync_event event used to synchronize exception catching.|
|Method||switch_and_set||Switch to a new sync_event and set the current one.|
|Method||set_ignored_exceptions||Declare which exceptions will be ignored.|
|Method||run||Overrides Thread.run to capture any exception.|
|Method||join||Overrides Thread.join to raise any exception caught.|
|Method||pending_exception||Raise the caught exception.|
When the thread uses an event to synchronize itself with another thread (setting it when the other thread can wake up from a wait call), the event must be set after catching an exception or the other thread will hang.
Some threads require multiple events and should set the relevant one when appropriate.
Note that the event should be initially cleared so the caller can wait() on him and be released when the thread set the event.
Also note that the thread can use multiple events, setting them as it progress, while the caller can chose to wait on any of them. What matters is that there is always one event set so that the caller is always released when an exception is caught. Re-using the same event is therefore risky as the thread itself has no idea about which event the caller is waiting on. If the caller has already been released then a cleared event won't guarantee that the caller is still waiting on it.
Using this method protects against race conditions while setting a new sync_event.
Note that this allows a caller to wait either on the old or the new event depending on whether it wants a fine control on what is happening inside a thread.
|Parameters||new||The event that will become sync_event|
Can be either:
Calling join(timeout=0) will raise the caught exception or return None if the thread is still alive.