ControllerCommand¶
-
class
lsst.ts.salobj.topics.ControllerCommand(salinfo, name, queue_len=100)¶ Bases:
lsst.ts.salobj.topics.ReadTopicRead a specified command topic.
Parameters: - salinfo :
SalInfo SAL component information
- name :
str Command name
- queue_len :
int, optional Number of elements that can be queued for
get_oldest.
Notes
Each command must be acknowledged by writing an appropriate
ackcmdmessage. If you use a callback function to process the command then this happens automatically. Otherwise you must call theackmethod to acknowledge the command yourself, though an initial acknowledgement withack=SalRetCode.CMD_ACKis always automatically sent when the command is read.After the initial acknowledgement with
ack=SalRetCode.CMD_ACK, automatic ackowledgement for callback functions works as follows:- If the callback function returns
Nonethen send a final acknowledgement withack=SalRetCode.CMD_COMPLETE. - If the callback function returns an acknowledgement
(instance of
SalInfo.AckType) instead ofNone, then send that as the final acknowledgement. This is very unusual, but might be useful if the callback wants to exit early and leave some background task or thread processing the rest of the command. - If the callback function raises
asyncio.TimeoutErrorthen send a final acknowledgement withack=SalRetCode.CMD_TIMEOUT. - If the callback function raises
asyncio.CancelledErrorthen send a final acknowledgement withack=SalRetCode.CMD_ABORTED. - If the callback function raises
ExpectedErrorthen send a final acknowledgement withack=SalRetCode.CMD_FAILEDandresult=f"Failed: {exception}". - If the callback function raises any other
Exceptionthen do the same asExpectedErrorand also log a traceback.
Attributes Summary
DataTypeThe type (class) for a message of this topic. allow_multiple_callbacksCan callbacks can run simultaneously? callbackCallback function, or None if there is not one. has_callbackReturn True if there is a callback function. has_dataHas any data been seen for this topic? max_historymetadataGet topic metadata as a TopicMetadata, if available, elseNone.Methods Summary
ack(data, ackcmd)Acknowledge a command by writing a new state. ackInProgress(data[, result])Deprecated version of ack_in_progress. ack_in_progress(data, *, timeout[, result])Ackowledge this command as “in progress”. aget([timeout])Get the current message, if any, else wait for the next message. close()Shut down and release resources. flush()Flush the queue of unread data. get([flush])Get the most recently seen message, or Noneif no data ever seen.get_oldest()Pop and return the oldest message from the queue, or Noneif the queue is empty.next(*[, timeout])Wait for data, returning old data if found. Attributes Documentation
-
DataType¶ The type (class) for a message of this topic.
When you read or write a message for this topic you are reading or writing an instance of
DataType.Notes
The preferred way to write a message for a topic is:
RemoteCommand.set_startto start a command.CommandEvent.set_putto write an event.CommandTelemetry.set_putto write a telemetry message.
However, it is also possible to use
DataTypeto create a message, then write, it as separate operations. For example, assuming we have aRemotefor SAL component “Test”:# The preferred way to issue a command: await = remote.cmd_wait.set_put(duration=2, timeout=5) # But an alternative is to first create the command, # then send it, as two separate operations: message = remote.cmd_wait.DataType(duration=2) await remote.cmd_wait.start(message, timeout=5) # Or, even more verbosely: message = remote.cmd_wait.DataType() message.duration = 2 await remote.cmd_wait.start(message, timeout=5)
-
allow_multiple_callbacks¶ Can callbacks can run simultaneously?
Notes
Ignored for synchronous callbacks because those block while running. In particular, if the callback is synchronous but launches one or more background jobs then the number of those jobs cannot be limited by this class.
-
callback¶ Callback function, or None if there is not one.
The callback function is called when a new message is received; it receives one argument: the message (an object of type
topics.BaseTopic.DataType).Raises: - TypeError
When setting a new callback if the callback is not None and is not callable.
Notes
The callback function can be synchronous or asynchronous (e.g. defined with
async def).Setting a callback flushes the queue, and it will remain empty as long as there is a callback.
get_oldestandnextare prohibited if there is a callback function. Technically they could both work, butget_oldestwould always returnNoneandnextwould miss messages if they arrived while waiting for something else. It seemed safer to just raise an exception.
-
has_callback¶ Return True if there is a callback function.
-
has_data¶ Has any data been seen for this topic?
Raises: - RuntimeError
If the
salinfohas not started reading.
-
max_history¶
Methods Documentation
-
ack(data, ackcmd)¶ Acknowledge a command by writing a new state.
Parameters: - data :
DataType Data for the command being acknowledged.
- ackcmd :
salobj.AckCmdType Command acknowledgement data.
- data :
-
ackInProgress(data, result='')¶ Deprecated version of ack_in_progress.
-
ack_in_progress(data, *, timeout, result='')¶ Ackowledge this command as “in progress”.
Parameters:
-
aget(timeout=None)¶ Get the current message, if any, else wait for the next message.
Parameters: - timeout :
float, optional Time limit, in seconds. If None then no time limit.
Returns: - data :
DataType The current or next message.
Raises: - RuntimeError
If a callback function is present, or if the
salinfohas not started reading.
Notes
Do not modify the returned data. To make a copy that you can safely modify, use
copy.copy(data).- timeout :
-
close()¶ Shut down and release resources.
Intended to be called by SalInfo.close(), since that tracks all topics.
-
flush()¶ Flush the queue of unread data.
Raises: - RuntimeError
If a callback function is present.
-
get(flush=True)¶ Get the most recently seen message, or
Noneif no data ever seen.Parameters: Returns: Raises: - RuntimeError
If the
salinfohas not started reading.
-
get_oldest()¶ Pop and return the oldest message from the queue, or
Noneif the queue is empty.Returns: Raises: - RuntimeError
If a callback function is present, or if the
salinfohas not started reading.
Notes
Use with caution when mixing with
next, since that also consumes data from the queue.
-
next(*, timeout=None)¶ Wait for data, returning old data if found.
Unlike
RemoteEvent.nextandRemoteTelemetry.next, the flush argument is not allowed; the only way to flush old commands is to callflush.Parameters: - timeout :
float, optional Time limit, in seconds. If None then no time limit.
Returns: - data :
DataType Command data.
Raises: - RuntimeError
If a callback function is present.
Notes
Do not modify the data or assume that it will be static. If you need a private copy, then copy it yourself.
- timeout :
- salinfo :