bluesky_queueserver.ReceiveConsoleOutput

class bluesky_queueserver.ReceiveConsoleOutput(*, zmq_subscribe_addr=None, zmq_topic='QS_Console', timeout=1000)[source]

The class allows to subscribe to published 0MQ messages and read the messages one by one as they arrive. Subscription is performed using the remote 0MQ address and topic.

The class provides blocking (with timeout) recv() method that waits for the next published message. The following example contains the code illustrating using the class. In real-world application the loop will be running in a separate thread and generating callbacks on each received message.

The subscribe() and unsubscribe() methods allow to explicitly subscribe and unsubscribe the socket to the topic. The messages published while the socket is unsubscribed are discarded. First call to recv() method automatically subscribes the socket.

from bluesky_queueserver import ReceiveConsoleOutput

zmq_subscribe_addr = "tcp://localhost:60625"
rco = ReceiveConsoleOutput(zmq_subscribe_addr=zmq_subscribe_addr)

while True:
    try:
        payload = rco.recv()
        time, msg = payload.get("time", None), payload.get("msg", None)
        # In this example the messages are printed in the terminal.
        sys.stdout.write(msg)
        sys.stdout.flush()
    except TimeoutError:
        # Timeout does not mean communication error!!!
        # Insert the code that needs to be executed on timeout (if any).
        pass
    # Place for the code that should be executed after receiving each
    #   message or after timeout (e.g. check a condition and exit
    #   the loop once the condition is satisfied).
Parameters:
zmq_subscribe_addrstr or None

Address of ZMQ server (PUB socket). If None, then the default address is tcp://localhost:60625 is used.

zmq_topicstr

0MQ topic for console output. Only messages from this topic are going to be received.

timeoutint, float or None

Timeout for the receive operation in milliseconds. If None, then wait for the message indefinitely.

__init__(*, zmq_subscribe_addr=None, zmq_topic='QS_Console', timeout=1000)[source]

Methods

__init__(*[, zmq_subscribe_addr, zmq_topic, ...])

recv([timeout])

Get the next published message.

subscribe()

Subscribe 0MQ socket to the console output topic.

unsubscribe()

Unsubscribe 0MQ socket from the console output topic.