.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. module:: wx.lib.delayedresult .. currentmodule:: wx.lib.delayedresult .. highlight:: python .. _wx.lib.delayedresult: ========================================================================================================================================== |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. :Copyright: (c) 2006 by Oliver Schoenborn :License: wxWidgets license :Version: 1.0 |function_summary| Functions Summary ==================================== ================================================================================ ================================================================================ :func:`~wx.lib.delayedresult.startWorker` Convenience function to send data produced by `workerFn(*wargs, **wkwargs)` ================================================================================ ================================================================================ | |class_summary| Classes Summary =============================== ================================================================================ ================================================================================ `~wx.lib.delayedresult.AbortedException` Raise this in your worker function so that the sender knows `~wx.lib.delayedresult.AbortEvent` Convenience class that represents a kind of threading.Event that `~wx.lib.delayedresult.DelayedResult` Represent the actual delayed result coming from the non-main thread. `~wx.lib.delayedresult.Handler` Bind some of the arguments and keyword arguments of a callable ('listener'). `~wx.lib.delayedresult.PreProcessChain` Represent a 'delayed result pre-processing chain', a kind of Handler. `~wx.lib.delayedresult.PreProcessChain.Traverser` Traverses the chain of pre-processors it is given, transforming `~wx.lib.delayedresult.Producer` Represent the worker thread that produces delayed results. `~wx.lib.delayedresult.Sender` Base class for various kinds of senders. A sender sends a result `~wx.lib.delayedresult.SenderCallAfter` This sender sends the delayed result produced in the worker thread `~wx.lib.delayedresult.SenderNoWx` Sender that works without wx. The results are sent directly, ie `~wx.lib.delayedresult.SenderWxEvent` This sender sends the delayed result produced in the worker thread `~wx.lib.delayedresult.Struct` An object that has attributes built from the dictionary given in ================================================================================ ================================================================================ | .. toctree:: :maxdepth: 1 :hidden: wx.lib.delayedresult.AbortedException wx.lib.delayedresult.AbortEvent wx.lib.delayedresult.DelayedResult wx.lib.delayedresult.Handler wx.lib.delayedresult.PreProcessChain wx.lib.delayedresult.PreProcessChain.Traverser wx.lib.delayedresult.Producer wx.lib.delayedresult.Sender wx.lib.delayedresult.SenderCallAfter wx.lib.delayedresult.SenderNoWx wx.lib.delayedresult.SenderWxEvent wx.lib.delayedresult.Struct Functions ------------ .. function:: 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.