mahos.node.node.Node#
- class mahos.node.node.Node(gconf: dict, name: NodeName, context: Context | None = None)#
Node is the main node type that runs in a loop and communicates with other nodes.
Node implements
main(), which is iterated until shutdown. If the loop should run at a constant rate (i.e. not a busy loop), rate management should be done insidemain().- Parameters:
gconf – global config dict.
name – name of this node.
- Variables:
conf – node’s local config.
ctx – communication context.
logger – configured logger.
Methods to be overridden
- main()#
Main procedure that will be looped.
Default implementation calls poll().
- close_resources()#
Close custom resources.
Important methods
- add_rep(handler: RepHandler | None = None, endpoint: str = 'rep_endpoint', req_type: Type[Request] | None = None)#
Add the reply handler for request of req_type at endpoint.
- add_pub(topic: bytes | str, endpoint: str = 'pub_endpoint') Publisher#
Add and return a Publisher for topic at endpoint.
- add_clients(*clis)#
Register internal NodeClient(s).
- poll()#
Poll inbound messages and call corresponding handlers.
this function can consume poll_timeout_ms if any inbound communication is registered.
Other methods
__init__(gconf, name[, context])close()Close this node.
fail_with(msg)log error and return failing response with same message.
main_event(shutdown_ev)Main loop that can be stopped by shutdown_ev.
main_interrupt()Main loop that can be stopped by KeyboardInterrupt.
set_shutdown()Shutdown this node, quitting from the main loop.
wait()Wait until required resources are ready.
Attributes
CLIENTThe class object for standard client.
TOPIC_TYPESMapping from topic-name to message type (class object) for the topic.