Skip to main content

Events and logs

The server pushes events as things happen: capture state, progress, the decoder list, annotations. The SDKs handle them for you, so most scripts never touch this API. Use it when you want to react to an event rather than wait for it.

Reached through workspace.events.

Events are replayed on attach

Events are replayed when you attach, so a client that connects late still sees the current state.

subscribe​

Calls your listener for every event, or for the kinds you name. Returns a function that unsubscribes.

def on_event(message):
print(message["type"], message)

stop = workspace.events.subscribe(on_event, only=["state", "progress"])
# ...
stop()
Do not block the listener

The listener runs on the connection's reader thread. Blocking it stalls every other message on that connection. Queue the work and return.

latest​

The most recent event of one kind, without waiting. The SDK keeps the last of each, so this is how you read state the server pushed before you asked.

config = workspace.events.latest("capture_config") # dict, or None
devices = workspace.events.latest("hw_devices")

wait_for​

Blocks until an event of a kind arrives, optionally one that satisfies a predicate. This is the building block behind capture.wait() and decoders.wait(), and what you want for a condition they do not cover.

# Wait until the trigger has fired at least 10 times.
event = workspace.events.wait_for(
"trigger_count",
predicate=lambda message: message.get("count", 0) >= 10,
timeout=60.0,
)

Errors: Timeout if nothing matching arrives in time.

Useful events​

The events a script usually cares about:

EventFires when
stateThe capture changes state. See Capture.
progressSamples come in.
pretrig_progressThe pre-trigger buffer is filling.
trigger_countThe trigger fired again, in normal mode.
capture_configA capture configuration was applied — the settled rate and trigger.
capture_refusedA capture was refused, with the reason.
decode_progressA decoder advanced. Throttled, but always sent at the end.
decodersThe decoder list changed.
annotationsMarkers or measurements changed, including recomputed results.
hw_devicesA device was plugged or unplugged. The complete list, every time.
io_progress, io_doneA save, load or export is running or has finished.
errorA command was refused. code is stable and meant to be matched on.
logThe server logged a line.

log​

The server's log for this workspace. The full history is replayed on attach, so you get the lines from before you connected too.

for line in workspace.events.log:
print(line)
The log is where a failing script explains itself

When a decoder or generator script misbehaves, the reason is usually in the server log rather than in the exception. ScriptError carries the relevant lines with it; the log has the rest.