ModPy API - modrpc/info GitHub Wiki
All functions for resource access are coroutines. Therefore, they should be called using "yield from" or "await" constructs.
result = await modpy.call("node0/get_temperature")
addr = await modpy.call("*/lookup_node", "node1")
init_node(**params)
-
str name
: name of the node -
int rpcport
: IP port for which this node can be accessed. -
str mcastip
: IP address which is used for message multicasting. -
int mcastport
: IP port used for message multicasting. -
asyncio.AbstractEventLoop loop
: In case external loop -
bool verbose
: Set verbose mode. -
bool debug
: Set debug mode in which debugging messages are printed.
Start running the
call(url, *args)
call
make a blocking call to the function at the given url. When the callee returns a value one can get the result. When url is of the form "*/resource", it will broadcast the request to all ModPy nodes on the local network. Multiple nodes can return values for this function call but only the first result will be returned to the calller.
When the target URL is not a function, a ModPy exception will be raised. For broadcasting calls, all exceptions will be ignored.
call_tm(url, timeout, *args)
call_nb(url, *args)
call_nb
makes a nonblocking call to the function at the given url, not waiting for the result. If the callee returns a value, it is ignored.
call_opt(url, callopt, *args)
call_opt
makes a call with the given option, callopt. callopt should be an instance of the CallOption
class, which controls the behavior of the function call.
- caller
- timeout
- ...
Each ModPy event has exactly one publisher and zero or more subscribers.
waitfor(*url)
EventInstance
. An EventInstance
instance contains two fields: key and value. The key is the url of the event which ocurred and value is the its value shipped with the event instance, if any. The value is None when the event publisher did not ship any value.
waitfor_tm
fire(url, *value)
ModPy depends on Python asyncio library and all ModPy resources are implemented as asyncio coroutines.
As an example, consider a ModPy function, say foo
.