Package park :: Package util :: Module threads

Module threads

source code

@threaded decorator for functions to be run in a thread.
Classes
  AfterThread
Thread class with additional 'after' capability which runs a function after the thread is complete.
Functions
 
threaded(fn)
@threaded decorator for functions to be run in a thread.
source code
 
daemon(fn)
@daemon decorator for functions to be run in a thread.
source code
 
demo(join=False) source code
 
test() source code
Function Details

threaded(fn)

source code 

@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.

daemon(fn)

source code 

@daemon decorator for functions to be run in a thread.

Returns the running thread.

Unlike threaded functions, daemon functions are not expected to complete.