pymasep.application.sub_app
Classes
Part of the application as a Thread. Usually a sub application is the engine or the interface. |
Module Contents
- class pymasep.application.sub_app.SubApp(app, received_q_id, cfg)
Bases:
threading.ThreadPart of the application as a Thread. Usually a sub application is the engine or the interface.
- Parameters:
app (App) – main application
received_q_id (int) – id of the queue used by the sub app to receive messages.
cfg (omegaconf.DictConfig) – configuration of the sub application
- id: str
id of the sub application
- config
configuration of the sub application
- app
main application pointer
- messages_received_q_id
id of the queue used to receive messages
- messages_received: queue.Queue
queue used to receive messages
- connected_sub_app
dict of sub applications information connected to this sub application
- current_event: pymasep.communication.message.Message | None = None
Last message received by the sub application
- app_states
possible states of the sub application
- current_app_states: List[pymasep.application.sub_app_state.SubAppState] = []
Stack of the current state of the sub application
- logger: logging.Logger
logger for the sub application
- environment: pymasep.common.environment.Environment | None = None
environment used to run the sub application
- remote_communication: pymasep.communication.base_threaded_communication.BaseThreadedCommunication | None = None
the remote communication of the sub application as a BaseThreadedCommunication (Client or Server)
- __del__()
Delete the instance. Close the logger
- register_connected_sub_app(sub_app_id, role, sent_q=None)
Register a sub application connected to self with a rale, and optionally a queue (if it’s the same process).
- Parameters:
sub_app_id (str) – Connected sub app id
role (str) – role of the connected sub app. See ConnectedSubAppInfo.
sent_q (Optional[queue.Queue]) – Queue of the connected sub app used to send messages (for sub apps in the same process)
- Return type:
None
- get_connected_id_from_agent_fname(agent_fname)
get the connected sub app that handles an agent
- Parameters:
agent_fname (str) – the agent full name (ex. state.agent_name)
- Returns:
the id of the sub app associated to the agent
- Return type:
str
- send_message(message, subapp_id)
Send messages to a sub app from its id. Send by queue or by socket according to the connection between the tow sub app
- Parameters:
message (pymasep.communication.message.Message) – Message to send
subapp_id (str) – destination sub app id
- Return type:
None
- static send_message_to_queue(message, q)
Send a message to a queue. The message is put in the queue as byte
:param message the message to send :param q the queue
- Parameters:
message (pymasep.communication.message.Message)
q (queue.Queue)
- Return type:
None
- wait_message(wanted_messages, block=True, most_recent=False, keep_all=None)
Wait for a message of certain types. The wait can be blocked or not. The received message is put in self.current_event
- Parameters:
wanted_messages (List[int]) – List of wanted messages types.
block (bool) – True if the method blocks until a message arrives
most_recent (bool) – True makes the function to get the most recent message in the queue and empty the queue
keep_all (Optional[List[int]]) – List of message types that will not be skipped when most_recent is True. All messages after the message with type in keep_all, are kept in the queue.
- Returns:
The received message
- Return type:
- get_current_app_state()
Get the current sub app state
- Returns:
The current sub app state as SubAppState
- push_state(sbapp_state)
Push a new state in the head state. Pause the current state and init the new one.
- Parameters:
sbapp_state (pymasep.application.sub_app_state.SubAppState) – New state to push
- Return type:
None
- set_state(sbapp_state)
Set a new state. Remove the ald current and push the new one.
- Parameters:
sbapp_state (pymasep.application.sub_app_state.SubAppState) – New state to set
- Return type:
None
- pop_state()
Clean and remove the current state
- Return type:
None