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>
A list of callbacks currently bound to the
The responsible object that executes the
add(callback : Callable)[source]¶
Adds a callback to the
remove(callback : Callable)[source]¶
Removes a callback from the
__call__(*args) → [ ... ][source]¶
Executes all connected callbacks in the order of addition, passing the
EventHandleras first argument and the optional args as second, third, … argument to them.
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.
MPEventHandlerrelies on the
multiprocessingmodule. If the module is not available in the target environment, a
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[source]¶
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.