Organizing Bluesky Startup Code
Detecting if the Code is Executed by RE Worker
Calling the is_re_worker_active()
API anywhere in the startup code or an imported module
allows to detect if the code is executed by RE Worker. The function returns True
if
the code is running in RE Worker environment and False
otherwise.
The API may be used to conditionally avoid execution of some code (e.g. the code that interacts with the user) when experiments are controlled remotely:
from bluesky_queueserver import is_re_worker_active
...
if is_re_worker_active():
<code without interactive features, e.g. reading data from a file>
else:
<code with interactive features, e.g. manual data input>
...
Note
Queue Server provides additional set_re_worker_active()
and clear_re_worker_active()
API,
which modify the value returned by subsequent calls to is_re_worker_active()
in the current process.
These API are intended for implementation of tests and should never be used in startup scripts.
The function can be used in startup scripts or modules to check if the script is imported or executed in RE Worker environment. |
|
Set the environment variable used to determine if the current process is RE Worker process. |
|
Clear the environment variable used to determine if the current process is RE Worker process. |
Detecting if the Code is Executed in IPython Kernel
The function is_ipython_mode()
returns True
if the code is executed in IPython environment
and False
if the environment is pure Python. The function corectly detects IPython
environment even if the code with patched IPython.get_ipython()
is loaded.
The function is used similarly to is_re_worker_active()
. The functions may be used
in startup code and uploaded scripts to identify whether the code is run in the worker environment
and whether the IPython features can be used.
The function can be used in startup scripts or modules to check if the script is running in IPython environment. |
|
Set the environment variable used to determine if the current process is RE Worker process. |
|
Clear the environment variable used to determine if the current process is RE Worker process. |