phoenix_title 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 wx.lib.delayedresult import startWorker
startWorker(consumer, workerFn)

More advanced uses:

  • The other parameters to startWorker()

  • Derive from Producer to override _extraInfo (e.g. to provide traceback info)

  • Create your own worker-function-thread wrapper instead of using Producer

  • Create your own Handler-like wrapper to pre- or post-process the result (see PreProcessChain)

  • Derive from Sender to use your own way of making result hop over the “thread boundary” (from non-main thread to main thread), e.g. using Queue

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

  1. 2006 by Oliver Schoenborn


wxWidgets license



function_summary Functions Summary


Convenience function to send data produced by workerFn(*wargs, **wkwargs)

class_summary Classes Summary


Raise this in your worker function so that the sender knows


Convenience class that represents a kind of threading.Event that


Represent the actual delayed result coming from the non-main thread.


Bind some of the arguments and keyword arguments of a callable (‘listener’).


Represent a ‘delayed result pre-processing chain’, a kind of Handler.


Traverses the chain of pre-processors it is given, transforming


Represent the worker thread that produces delayed results.


Base class for various kinds of senders. A sender sends a result


This sender sends the delayed result produced in the worker thread


Sender that works without wx. The results are sent directly, ie


This sender sends the delayed result produced in the worker thread


An object that has attributes built from the dictionary given in


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.