ScriptInfo

class lsst.ts.scriptqueue.ScriptInfo(log, remote, index, seq_num, is_standard, path, config, descr, log_level=0, pause_checkpoint='', stop_checkpoint='', verbose=False)

Bases: object

Information about a loaded script.

Parameters:
log : logging.Logger

Logger.

remote : salinfo.Remote

Remote for the “Script” component with index=0. This will be used to send commands but not receive events, since the queue model does that.

index : int

Index of script. This must be unique among all Script SAL components that are currently running.

seq_num : int

Command sequence number; recorded in the script info.

is_standard : bool

Is this a standard (True) or external (False) script?

path : str, bytes or os.PathLike

Path to script, relative to standard or external root dir.

config : str

Configuration data as a YAML encoded string.

descr : str

A short explanation of why this script is being run.

log_level : int (optional)

Log level for the script, as a Python logging level. 0, the default, leaves the level unchanged.

pause_checkpoint : str (optional)

Checkpoint(s) at which to pause, as a regular expression. No checkpoints if blank; all checkpoints if “.*”.

stop_checkpoint : str (optional)

Checkpoint(s) at which to stop, as a regular expression. No checkpoints if blank; all checkpoints if “.*”.

verbose : bool (optional)

If True then print log messages from the script to stdout.

Attributes Summary

callback Set, clear or get a function to call whenever the script state changes.
configure_failed True if the configure command failed.
configured True if the configure command succeeded.
failed True if the script failed.
load_failed True if the script could not be loaded.
needs_group_id Is this script ready to be assigned a group ID?
process_done True if the script process was started and is done.
process_state State of the script subprocess.
runnable Can the script be run?
running True if the script was commanded to run and is not done.
setting_group_id Return True if the group ID is being set.
started True if the script was commanded to run or terminate.
terminated True if the script was terminated.

Methods Summary

clear_group_id(command_script) Clear the group ID.
run() Start the script running.
set_group_id(group_id) Set the group ID.
start_loading(fullpath) Start the script process and start a task that will configure the script when it is ready.
terminate() Terminate the script.

Attributes Documentation

callback

Set, clear or get a function to call whenever the script state changes.

It receives one argument: this ScriptInfo. Set to None to clear the callback.

configure_failed

True if the configure command failed.

configured

True if the configure command succeeded.

failed

True if the script failed.

This will be false if the script was terminated.

load_failed

True if the script could not be loaded.

needs_group_id

Is this script ready to be assigned a group ID?

True if the script is configured and not started, and the group ID is neither set nor being set.

process_done

True if the script process was started and is done.

Notes

This will be true if the script fails or is terminated after the process has been created. This will be false if the script is terminated before the process has been created.

process_state

State of the script subprocess.

One of the ScriptProcessState enumeration constants.

runnable

Can the script be run?

For a script to be runnable it must be configured, not started, and it must have a group ID.

running

True if the script was commanded to run and is not done.

setting_group_id

Return True if the group ID is being set.

started

True if the script was commanded to run or terminate.

terminated

True if the script was terminated.

Notes

If this is true the termination may be in progress. To wait until termination is complete:

if self.terminated and not self.process_done:
    await self.process_task

Methods Documentation

clear_group_id(command_script)

Clear the group ID.

Can be called in any state.

Parameters:
command_script : bool

If True and if the script is configured and not started, then send setGroupId command to the script.

run()

Start the script running.

Raises:
RuntimeError

If the script cannot be run, e.g. because:

  • The script has not yet been configured.
  • run was already called.
  • The script process is done.
set_group_id(group_id)

Set the group ID.

Also creates self.set_group_id_task and sets it done on success or to an exception if the setGroupId Script command fails.

Parameters:
group_id : str

New group ID; “” to clear the group ID.

Raises:
RuntimeError

If the script is not in state CONFIGURED.

asyncio.TimeoutError

If the command or reply takes too long.

start_loading(fullpath)

Start the script process and start a task that will configure the script when it is ready.

Parameters:
fullpath : str, bytes or os.PathLike

Full path to the script.

Notes

If loading is canceled the script process is terminated. If loading fails the script is marked as terminated.

terminate()

Terminate the script.

Does not wait for termination to finish; to do that use:

if script_info.process is not None:
    await script_info.process.wait()
Returns:
did_terminate : bool

Returns True if the script was terminated (possibly by an earlier call to terminate), False if the script process finished before being terminated.

Notes

If the process has finished then do nothing. Otherwise set self._terminate to True and:

  • If the process is running then terminate it by sending SIGTERM.
  • If the process is being started then cancel that.