hbp_nrp_simserver.server.simulation_server module

This module implements the Simulation Server application. It is managed by a SimulationServerInstance.

class hbp_nrp_simserver.server.simulation_server.SimulationServer(sim_settings: hbp_nrp_simserver.server.SimulationSettings)[source]

Bases: object

STATUS_UPDATE_INTERVAL = 1.0
initialize(except_hook=None)[source]
Initialize the simulation server:
  • parse and validate the experiment configuration file

  • create the MQTT notifier

  • create NRPScriptRunner

  • create SimulationServerLifecycle

  • start the status update timer

If anything goes wrong, the relative exception will be re-raised

Parameters

except_hook – A handler method for critical exceptions

property is_initialized
property lifecycle

Gets the lifecycle instance representing the current SimulationServer

property nrp_script_runner

Gets the nrp_script_runner used by the server

publish_error(msg: str, error_type: str, line_number: int = - 1, offset: int = - 1, line_text: str = '')[source]

Sends an error message to clients (e.g. frontend)

Parameters
  • msg – The error message

  • error_type – The error type, e.g. “Runtime”

  • line_number – The line number where the error occurred

  • offset – The offset

  • line_text – The text of the line causing the error

publish_state_update()[source]

Publish the simulation state and stats

property real_time
Returns

the wall-clock time of the simulation if initialized, 0 otherwise

run()[source]

This method blocks the caller until the simulation is finished

shutdown()[source]
property simulation_id

Gets the simulation ID, as configured in sim_settings, that is serviced.

property simulation_time
Returns

the simulation time if initialized, 0 otherwise

property simulation_time_remaining
Returns

the simulation time left until the timeout if initialized, 0 otherwise

hbp_nrp_simserver.server.simulation_server.main()[source]