bluesky.plan_stubs.call_in_thread#

bluesky.plan_stubs.call_in_thread(func: ~collections.abc.Callable[[~P], ~bluesky.protocols.T], /, *args: ~typing.~P, **kwargs: ~typing.~P) → Generator[Msg, Any, T][source]#

Call a blocking function in a worker thread and return its result.

Unlike calling func directly in a plan, this keeps the RunEngine’s event loop free while func runs. An exception raised by func is raised in the plan.

func is called exactly once. If the plan is paused or suspended while func runs, func keeps running, and on resume the plan waits for it instead of calling it again. If the plan is aborted, stopped or halted, func is not interrupted: it runs to completion in the background, and the Python process cannot exit until it returns. Give long-running functions their own timeout.

func runs outside the RunEngine’s message stream: devices it moves are not stopped on pause, abort or halt, statuses it creates are not tracked by wait, and values it reads are not recorded in documents.

Parameters:
funccallable

blocking function to call

args

passed to func

kwargs

passed to func

Returns:
result

the return value of func. If no RunEngine runs the plan (for example list(plan)), func is not called and this is None.

Yields:
msgMsg

Msg('wait_for', ...). The RunEngine starts func the first time it processes this message; if a pause interrupts the wait, the message is yielded again until func returns.