pymasep.application
Submodules
Classes
Part of the application as a Thread. Usually a sub application is the engine or the interface. |
|
This class implements the concept (pretty much) of Game State but in the sub app level. |
|
Information of a sub application connected to another one. |
Package Contents
- class pymasep.application.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
- class pymasep.application.SubAppState(sub_application)
This class implements the concept (pretty much) of Game State but in the sub app level.
- Parameters:
sub_application (pymasep.application.SubApp) – the sub application where the state is defined
- sub_application
the sub application where the state is defined
- active = False
if the state is active or not
- init()
Initialisation of the state
- Return type:
None
- abstract update()
the update phase of the state, where variables change
- Return type:
None
- abstract render(time_delta)
the render part : how to display the state
- Parameters:
time_delta (float) – the time delta since the last render
- Return type:
None
- pause()
Pause the state
- Return type:
None
- clean()
The state is destroyed. Clean all elements of the state
- Return type:
None
- class pymasep.application.ConnectedSubAppInfo(sub_app_id, role, msg_queue=None, agent_fname=None)
Information of a sub application connected to another one.
- Parameters:
sub_app_id (str) – the id of the connected sub app.
role (str) – the role of the connected sub app. See ROLE_* bellow for more information.
msg_queue (queue.Queue) – the queue to send messages (in the case of intra process sub app).
agent_fname (str) – the agent fullname managed by the sub app (for interface connected sup app, None otherwise).
- ROLE_NONE = 'None'
No role. Testing only
- ROLE_OBSERVER = 'Observer'
The connected sub app is an Interface as observer. No action cannot be send to engine.
- ROLE_ACTOR = 'Actor'
The connected sub app is an Interface as actor. Engine will take into account the action send.
- ROLE_SERVER = 'Server'
The connected sub app is the engine
- id: str
the id of the connected sub app
- role: str
The role of the connected sub app
- queue: queue.Queue
The queue to send message (for the case of intra process sub app)
- agent_fname
The agent fullname managed by the sub app (for interface)
- last_info_sent
data about sent information to this sub_app by the engine