Derive the class from CallbackService instead of Service to support callback functionality. All methods decorated with callback are wrapped by CallbackFunction.
Here is an example:
class TestService(CallbackService):
@callback
def callback_function(self, *args, **kwargs):
# do some stuff
Note
For an extensive example see Callback Service Example.
Warning
It is not possible to start a CallbackService in multiplex mode, because that would lead to deadlocks.
To perform the communication with Pyro4 there must be a CallbackServer running. Use the with-statement:
with CallbackServer():
# do some stuff
Or start and stop the server manually:
CallbackServer.start()
# do some stuff
CallbackServer.stop()
Classes which should provide callback functionality have to be derived from CallbackObject and the callback functions have to be decorated with callback to be wrapped by CallbackFunction.
Here is an example:
class TestObject(CallbackObject):
@callback
def callback_function(self, *args, **kwargs):
# do some stuff
Note
For an extensive example see Callback Object Example.
Just call call(). See also Callback Object Example or Queued Callback Example..
Events join several callbacks together. To get callbacks from that event you just have to register():
If trigger() is called, the call is forwarded to all registered callbacks:
The caller doesn’t have to care how many callbacks are registered. Doesn’t matter if there are no registered callbacks at all.
Note
Each callback is executed in its own thread and errors are logged.
Marks class method as callback function
Wraps a function and registers at the CallbackServer or the given Pyro4.Daemon.
Parameters : | func : callable
daemon : Pyro4.Daemon
|
---|
Notes
Can be called like normal functions
Callbacks are called using autoproxy feature of Pyro4. As Pyro4 does only support function calls, an additional call() function is provided.
Methods
Calls the wrapped function with given args and kwargs.
Returns a unique id for this callback
Wraps all methods decorated with callback with a CallbackFunction
Manages a thread with a daemon to serve callbacks
Implements the singleton pattern.
Static Methods
Register the given CallbackFunction at the server
Parameters : | cb_func : CallbackFunction
|
---|
Starts the server
Raises : | exc : CallbackServerAlreadyRunningError
|
---|
Stops the server
Raises : | exc : CallbackServerNotRunningError
|
---|
Register the given CallbackFunction at the server
Parameters : | cb_func : CallbackFunction
|
---|
Bases: Service
Service that wraps all methods decorated with callback with a CallbackFunction
Parameters : | multiplex : bool
async : bool
|
---|