TimedRunner#

class wattson.apps.script_controller.runner.timed_runner.TimedRunner(controller: ScriptControllerApp, sleep: float = 0.1)#

Bases: Thread

Methods

__init__

This constructor should always be called with keyword arguments.

add_action

Queues an action to run at the specified time.

add_script

start_date, speed = script.get_simulated_time_info() if speed is None and self._sim_speed is None: speed = 1 if start_date is not None: o_start_date = self._wattson_time self._wattson_time = start_date if type(start_date) == float else start_date.timestamp() if o_start_date is not None and start_date != o_start_date: self._default_logger.warning("Different scripts requested different start times: " f"{self._wattson_time} vs {o_start_date}") if speed is not None: if self._sim_speed is not None and speed != self._sim_speed: self._default_logger.warning(f"Different scripts requested different simulated speeds: " f"({speed} vs {self._sim_speed})!") self._sim_speed = speed

begin_scope

end_scope

get_controller

run

Method representing the thread's activity.

set_scope_logger

start

Start the thread's activity.

__init__(controller: ScriptControllerApp, sleep: float = 0.1)#

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

add_action(script: TimedScript | None, at: datetime | str | float | int, action: Callable, logger: Optional = None, apply_sim_offset: bool = True)#

Queues an action to run at the specified time.

Parameters:
  • script (Optional['TimedScript']) – The script that adds this action. Required for relative timings. None defaults all timings to the Simulated Start Time

  • at (Union[datetime, str, float, int]) – Timing information. Either a datetime (in simulated time!), a str representing simulated time in Y-m-d H:M:S format, or a relative float specifying the simulated time offset from the script’s start.

  • action (Callable) – The action to trigger

  • logger (Optional, optional) – An optional logger to pass to the action. Uses a global logger if no specific one is provided. (Default value = None)

  • apply_sim_offset (bool, optional) – Whether the timing should be offset with respect to the simulated time (Default value = True)

add_script(script: TimedScript)#

start_date, speed = script.get_simulated_time_info() if speed is None and self._sim_speed is None: speed = 1 if start_date is not None: o_start_date = self._wattson_time self._wattson_time = start_date if type(start_date) == float else start_date.timestamp() if o_start_date is not None and start_date != o_start_date: self._default_logger.warning(“Different scripts requested different start times: “ f”{self._wattson_time} vs {o_start_date}”) if speed is not None: if self._sim_speed is not None and speed != self._sim_speed: self._default_logger.warning(f”Different scripts requested different simulated speeds: “ f”({speed} vs {self._sim_speed})!”) self._sim_speed = speed

Parameters:

script ('TimedScript') –

run() None#

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

start() None#

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.