Skip to content

Instantly share code, notes, and snippets.

@danielballan
Created July 17, 2021 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielballan/c1da066f52541a1a28e79ed5a95b8a23 to your computer and use it in GitHub Desktop.
Save danielballan/c1da066f52541a1a28e79ed5a95b8a23 to your computer and use it in GitHub Desktop.
MVP for Qt RemoteDispatcher

Terminal 1:

bluesky-0MQ-proxy 5567 5568

Terminal 2:

python publisher.py
# Prints a stready stream of documents

Terminal 3:

python dispathcer.py
# Prints a steady stream of documents and updates like:
Run list has 16 items
from bluesky_widgets.models.utils import RunList
from bluesky_widgets.utils.streaming import stream_documents_into_runs
from bluesky_widgets.qt.zmq_dispatcher import RemoteDispatcher
from bluesky_widgets.qt import gui_qt
rl = RunList()
def log(name, doc):
print(name, doc)
print(f"Run list has {len(rl)} items")
with gui_qt("Example"):
d = RemoteDispatcher("localhost:5568")
callback = stream_documents_into_runs(rl.append)
d.subscribe(callback)
d.subscribe(log)
d.start()
from bluesky.plans import scan
from ophyd.sim import motor, det
from bluesky import RunEngine
from bluesky.callbacks.zmq import Publisher
motor.delay = 0.2
def plan():
while True:
yield from scan([det], motor, -5, 5, 1)
RE = RunEngine()
publisher = Publisher("localhost:5567")
RE.subscribe(publisher)
RE.subscribe(print)
RE(plan())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment