ibex_bluesky_core.run_engine
Utilities for the bluesky run engine, configured for IBEX.
Members
Acquire a RunEngine in a suitable configuration for ISIS experiments. |
|
Run a plan. |
- ibex_bluesky_core.run_engine.get_run_engine() RunEngine [source]
Acquire a RunEngine in a suitable configuration for ISIS experiments.
This function should always be used in preference to creating a bluesky run engine manually.
This function is cached, meaning that the same run engine (using the same underlying event loop) will be used if this function is called multiple times. Creating multiple RunEngines is unlikely to be desired behaviour, though we cannot prevent users from creating a RunEngine from bluesky directly.
Basic usage:
Get the IBEX run engine:
RE = get_run_engine()
Run a plan:
from bluesky.plans import count # Or any other plan det = ... # A "detector" object, for example a Block or Dae device. RE(count([det]))
Control the state of the run engine:
RE.abort(reason="...") # Stop a plan, do cleanup, and mark as failed (e.g. bad data). RE.stop() # Stop a plan, do cleanup, mark as success"(e.g. scan has moved past peak). RE.halt() # Stop a plan, don't do any cleanup, just abort with no further action. RE.resume() # Resume running a previously-paused plan.
Subscribe to data emitted by this run engine:
RE.subscribe(lambda name, document: ...)
For full documentation about the run engine, see:
- ibex_bluesky_core.run_engine.run_plan(plan: Generator[Msg, Any, Any], **metadata_kw: Any) RunEngineResult [source]
Run a plan.
Warning
The usual way to run a plan in bluesky is by calling
RE(plan(...))
interactively. AnRE
object is already available in recent versions of the IBEX user interface, or can be acquired by callingget_run_engine()
.Use of this function is not recommended, but it is nevertheless provided as an escape hatch for workflows which would otherwise be difficult to express or where parts of scanning scripts have not, or cannot, be migrated to bluesky.
- Parameters:
plan (positional-only) – The plan to run. This is typically a generator instance.
metadata_kw (optional, keyword-only) – Keyword arguments (metadata) to pass to the bluesky run engine.
- Returns:
A
RunEngineResult
instance. The return value of the plan can then be accessed using theplan_result
attribute.- Raises:
RuntimeError – if the run engine was not idle at the start of this call.
RuntimeError – if a reentrant call to the run engine is detected.
bluesky.utils.RunEngineInterrupted – if the user, or the plan itself, explicitly requests an interruption.
Calling a plan using this function means that keyboard-interrupt handling will be degraded: all keyboard interrupts will now force an immediate abort of the plan, using
RE.abort()
, rather than giving the possibility of gracefully resuming. Cleanup handlers will execute during theRE.abort()
.The bluesky run engine is not reentrant. It is a programming error to attempt to run a plan using this function, from within a plan. To call a sub plan from within an outer plan, use:
def outer_plan(): ... yield from subplan(...)