ModPy API - modrpc/info GitHub Wiki

Table of Contents

Overview

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")

ModPy Node Management

init_node

init_node(**params)
Create a node with optional parameters. A paramter can be one
  • 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_node

Start running the

Node class

API For Functions

call

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

call_tm(url, timeout, *args)

call_nb

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

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.

CallOption

CallContext

  • caller
  • timeout
  • ...

API for Events

Each ModPy event has exactly one publisher and zero or more subscribers.

waitfor

waitfor(*url)
Waits for the given events until any of the given events occurs. The result will be an instance of 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

waitfor_tm

fire

fire(url, *value)
url must be of the form "./<resource></resource>" or "<resource></resource>" since the event should be fired by local publisher. Events can never be fired by remote nodes.

EventInstance

API for Processes

start

suspend

resume

kill

API to be used in a different thread

ModPy depends on Python asyncio library and all ModPy resources are implemented as asyncio coroutines. As an example, consider a ModPy function, say foo.

⚠️ **GitHub.com Fallback** ⚠️