Package wx :: Package lib :: Module delayedresult
[frames | no frames]

Module wx.lib.delayedresult

This module supports the thread-safe, asynchronous transmission of data ('delayed results') from a worker (non-GUI) thread to the main thread. Ie you don't need to mutex lock any data, the worker thread doesn't wait (or even check) for the result to be received, and the main thread doesn't wait for the worker thread to send the result. Instead, the consumer will be called automatically by the wx app when the worker thread result is available.

In most cases you just need to use startWorker() with the correct parameters (your worker function and your 'consumer' in the simplest of cases). The only requirement on consumer is that it must accept a DelayedResult instance as first arg.

In the following example, this will call consumer(delayedResult) with the return value from workerFn:

from delayedresult import startWorker
startWorker(consumer, workerFn)

More advanced uses:

Thanks to Josiah Carlson for critical feedback/ideas that helped me improve this module.


Version:

1.0

Copyright:

  1. 2006 by Oliver Schoenborn

License:

wxWidgets license

Classes
DelayedResult Represent the actual delayed result coming from the non-main thread.
Handler Bind some of the arguments and keyword arguments of a callable ('listener').
PreProcessChain Represent a 'delayed result pre-processing chain', a kind of Handler.
Producer Represent the worker thread that produces delayed results.
Sender Base class for various kinds of senders.
SenderCallAfter This sender sends the delayed result produced in the worker thread to a callable in the main thread, via wx.CallAfter.
SenderNoWx Sender that works without wx.
SenderWxEvent This sender sends the delayed result produced in the worker thread to an event handler in the main thread, via a wx event of class eventClass.

Function Summary
  startWorker(consumer, workerFn, cargs, ckwargs, wargs, wkwargs, jobID, group, daemon, sendReturn, senderArg)
Convenience function to send data produced by workerFn(*wargs, **wkwargs) running in separate thread, to a consumer(*cargs, **ckwargs) running in the main thread.

Function Details

startWorker(consumer, workerFn, cargs=(), ckwargs={}, wargs=(), wkwargs={}, jobID=None, group=None, daemon=False, sendReturn=True, senderArg=None)

Convenience function to send data produced by workerFn(*wargs, **wkwargs) running in separate thread, to a consumer(*cargs, **ckwargs) running in the main thread. This function merely creates a SenderCallAfter (or a SenderWxEvent, if consumer derives from wx.EvtHandler), and a Producer, and returns immediately after starting the Producer thread. The jobID is used for the Sender and as name for the Producer thread. Returns the thread created, in case caller needs join/etc.


Generated by Epydoc 2.1.20050511.rpd on Mon Feb 16 12:54:33 2009 http://epydoc.sf.net