General purpose event handling routines¶
A simple event handling class, which manages callbacks to be executed.
The EventHandler does not need to be kept as separate instance, but is mainly intended to be used as attribute in event-aware class objects.
>>> def myfunc(sender): ... print("event triggered by %s" % sender) ... >>> class MyClass(object): ... def __init__(self): ... self.anevent = EventHandler(self) ... >>> myobj = MyClass() >>> myobj.anevent += myfunc >>> myobj.anevent() event triggered by <__main__.MyClass object at 0x801864e50>
__call__(*args) → [ ... ]¶
This will return a list containing the return values of the callbacks in the order of their execution.
An asynchronous event handling class based on
EventHandler, in which callbacks are executed in parallel. It is the responsibility of the caller code to ensure that every object used maintains a consistent state. The
MPEventHandlerclass will not apply any locks, synchronous state changes or anything else to the arguments or callbacks being used. Consider it a “fire-and-forget” event handling strategy.
Also, please be aware of the restrictions that apply to the
multiprocessingmodule; arguments and callback functions for example have to be pickable, etc.
__call__(*args) → AsyncResult¶
Executes all connected callbacks within a
multiprocessing.pool.Pool, passing the
senderas first argument and the optional args as second, third, … argument to them.
This will return a
multiprocessing.pool.AsyncResultcontaining the return values of the callbacks in the order of their execution.