|
@threaded decorator for functions to be run in a thread.
Returns the running thread.
The returned thread supports the following methods:
wait(timeout=False)
Waits for the function to complete.
Returns the result of the function if the thread is joined,
or None if timeout. Use thread.isAlive() to test for timeout.
after(notify)
Calls notify after the thread is complete. Notify should
take a single argument which is the result of the function.
isAlive()
Returns True if thread is still running.
name
Thread name property. By default the name is 'fn-#' where fn
is the function name and # is the number of times the thread
has been invoked.
For example:
@threaded
def compute(self,input):
...
def onComputeButton(self,evt):
thread = self.compute(self.input.GetValue())
thread.after(lambda result: wx.Post(self.win,wx.EVT_PAINT))
A threaded function can also be invoked directly in the current thread:
result = self.compute.main(self.input.GetValue())
All threads must complete before the program can exit. For queue
processing threads which wait are alive continuously waiting for
new input, use the @daemon decorator instead.
|