mahos.node.node.Node#

class mahos.node.node.Node(gconf: dict, name: NodeName, context: Context | None = None)#

Node is the main type of Nodes that works in the loop and communicates each other.

Node implements main() function that is iterated until shutdown. If loop should be at constant rate (i.e. not busy loop), the rate management should be done inside main() function.

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

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.

poll()

Poll inbound messages and call corresponding handlers.

set_shutdown()

Shutdown this node, quitting from the main loop.

wait()

Wait until required resources are ready.

Attributes

CLIENT

The class object for standard client.

TOPIC_TYPES

Mapping from topic-name to message type (class object) for the topic.