Engine¶
Run engine¶
RunEngine
¶
Bases: RunEngine
Runs plans and emits documents without blocking the calling thread.
Wraps bluesky.run_engine.RunEngine: __call__ runs the plan on a
separate thread and returns a concurrent.futures.Future of its result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md
|
dict[str, Any]
|
Metadata store, a |
None
|
loop
|
AbstractEventLoop | None
|
Event loop plans run on. Defaults to the shared background loop. |
None
|
preprocessors
|
list
|
Generator functions modifying a plan's messages, such as the
|
None
|
md_validator
|
Callable[dict[str, Any], None]
|
Raises to prevent a run whose metadata it finds invalid; its return value is ignored. |
None
|
md_normalizer
|
Callable[dict[str, Any], dict[str, Any]]
|
Like md_validator, raises for invalid metadata; otherwise returns the normalized metadata. |
None
|
scan_id_source
|
Callable[dict[str, Any], int | Awaitable[int]]
|
Function, possibly async, returning the next scan_id. By default scan_id increments by 1. |
default_scan_id_source
|
call_returns_result
|
bool
|
What the Future |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
md |
The metadata store described above. |
|
record_interruptions |
False by default. True adds an event stream recording interruptions (pauses, suspensions). |
|
state |
{'idle', 'running', 'paused'} |
|
suspenders |
Read-only collection of |
|
preprocessors |
list
|
The preprocessors described above. |
msg_hook |
|
|
state_hook |
|
|
waiting_hook |
|
|
ignore_callback_exceptions |
Boolean, False by default. |
|
loop |
asyncio event loop
|
e.g., |
max_depth |
Maximum stack depth, preventing calls to the RunEngine from inside a
function, which breaks introspection. None by default; 2 suits the
Python interpreter and 11 |
|
pause_msg |
str
|
Message printed when a run is interrupted, with instructions for
changing the RunEngine's state. |
commands |
The list of commands available to Msg. |
Source code in src/redsun/engine/_wrapper.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
resume
¶
Resume the paused plan on a separate thread.
Pausing completes the future __call__ returned, so this returns a
new one.
Returns:
| Type | Description |
|---|---|
``Future[RunEngineResult | tuple[str, ...]]``
|
Future of the resumed plan's result. |
Source code in src/redsun/engine/_wrapper.py
Actions¶
Decorators and types for continuous, interactive plans.
A continuous plan loops until stopped, and may be paused and resumed and take actions the user triggers while it runs.
SRLatch: anasyncioset-reset latch synchronising a plan with outside signals.continous: marks a plan as continuous, recording whether it istogglableandpausable.Action: a dataclass describing one action (name, description, toggle state).ContinousPlan: atyping.Protocoltyping decorated plans, also usable withisinstance.
Action
dataclass
¶
Metadata for an in-flight action on a continuous plan.
An Action is something the user triggers while a continuous plan runs. It
holds an SRLatch, so the plan can await the trigger.
Warning
The latch is created on first access of event_map, so an Action can
be constructed without a running event loop. Access the latch only from
inside a plan.
Subclass it to add fields.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the action. |
description |
str
|
Short description of the action, usable as a tooltip. |
togglable |
bool
|
Whether the action is togglable. |
toggle_states |
tuple[str, str]
|
Labels of the toggle states (on, off), used when |
Source code in src/redsun/engine/actions.py
SRLatch
¶
An asyncio set-reset latch.
Two asyncio.Event objects let a coroutine wait for either the set or the
reset state. A new latch is reset.
Source code in src/redsun/engine/actions.py
ContinousPlan
¶
Bases: Protocol[P, R_co]
Protocol for plans decorated with continous.
The return type of continous, also usable with isinstance:
Attributes:
| Name | Type | Description |
|---|---|---|
__togglable__ |
bool
|
Whether the plan loops until the run engine stops it. |
__pausable__ |
bool
|
Whether the run engine can pause and resume the plan. |
Source code in src/redsun/engine/actions.py
continous
¶
continous(
func: Callable[P, R_co] | None = None,
/,
*,
togglable: bool = True,
pausable: bool = False,
) -> (
Callable[[Callable[P, R_co]], ContinousPlan[P, R_co]]
| ContinousPlan[P, R_co]
)
Mark a plan as continuous.
A continuous plan gets UI controls to start, stop, pause and resume it. Usable with or without arguments:
@continous
def my_plan() -> MsgGenerator[None]: ...
@continous(togglable=True, pausable=True)
def my_plan(detectors: Sequence[DetectorProtocol]) -> MsgGenerator[None]: ...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
togglable
|
bool
|
Whether the plan loops until stopped with a toggle button. |
True
|
pausable
|
bool
|
Whether the run engine can pause and resume the plan. |
False
|
Returns:
| Type | Description |
|---|---|
ContinousPlan
|
The decorated plan function, typed as a |
Notes
The signature is untouched; the flags are stored on the function as
__togglable__ and __pausable__.
Source code in src/redsun/engine/actions.py
Plan stubs¶
Plan stubs adding action flow control to bluesky.plan_stubs.
wait_for_actions and read_while_waiting wait on user actions. Every stub is
a generator yielding Msg objects, used inside larger plans with
yield from.
wait_for_actions
¶
wait_for_actions(
events: Mapping[str, SRLatch],
timeout: float = SIXTY_FPS,
wait_for: Literal["set", "reset"] = "set",
) -> MsgGenerator[tuple[str, SRLatch]]
Wait for any of the given latches to change state.
Polls every timeout seconds until a latch changes, then returns its name and latch. The plan yields control on each poll, so background tasks keep running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Mapping[str, SRLatch]
|
Mapping of action names to their |
required |
timeout
|
float
|
Polling interval in seconds, 1/60 s by default. |
SIXTY_FPS
|
wait_for
|
Literal['set', 'reset']
|
Whether to wait for a latch to be set or reset. |
'set'
|
Returns:
| Type | Description |
|---|---|
tuple[str, SRLatch]
|
The name and latch that changed state. |
Source code in src/redsun/engine/plan_stubs.py
describe
¶
Gather the descriptor from a Readable device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Readable[Any]
|
The device to describe. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Descriptor]
|
The descriptor dict returned by |
Source code in src/redsun/engine/plan_stubs.py
describe_collect
¶
describe_collect(
obj: Collectable,
) -> MsgGenerator[
dict[str, Descriptor] | dict[str, dict[str, Descriptor]]
]
Gather descriptors from a Collectable device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Collectable
|
The device to describe. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Descriptor] | dict[str, dict[str, Descriptor]]
|
The descriptor dict returned by |