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
loglogging.Logger

Logger.

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

indexint

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

seq_numint

Command sequence number; recorded in the script info.

is_standardbool

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

pathstr, bytes or os.PathLike

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

configstr

Configuration data as a YAML encoded string.

descrstr

A short explanation of why this script is being run.

log_levelint (optional)

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

pause_checkpointstr (optional)

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

stop_checkpointstr (optional)

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

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

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_scriptbool

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.

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_idstr

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.

async start_loading(fullpath)

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

Parameters
fullpathstr, 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.

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_terminatebool

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