ScriptInfo#

class lsst.ts.scriptqueue.ScriptInfo(log, remote, index, seq_num, is_standard, path, config, descr, block='', 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.

  • block (str) – Name of the observing block the script is part of, e.g. BLOCK-000.

  • 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 callback coroutine (async 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_block_id(block_id)

Set block id, this is unique identifier for a block execution.

set_block_index(block_index)

Set the block index for this script.

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 and wait for the process to terminate.

Attributes Documentation

callback#

Set, clear or get a callback coroutine (async function) to call whenever the script state changes.

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

Raises:

TypeError – If callback is not a coroutine

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.

Return type:

None

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.

Return type:

None

set_block_id(block_id)#

Set block id, this is unique identifier for a block execution.

Parameters:

block_id (str) – Unique identifier for block execution.

Return type:

None

set_block_index(block_index)#

Set the block index for this script.

Parameters:

block_index (int) – Block index.

Return type:

None

async 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:
Return type:

None

async 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.

Return type:

None

Notes

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

async terminate()#

Terminate the script and wait for the process to terminate.

If terminating the script process takes longer than _TERMINATE_TIMEOUT, log a warning and stop waiting.

Returns:

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

Return type:

bool

Notes

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

  • If the process is starting, wait for it to start.

  • If the process is running, terminate it by sending SIGTERM.

  • Call the callback function, if any.