diff --git a/force_bdss/core_plugins/dummy/ui_notification/ui_notification.py b/force_bdss/core_plugins/dummy/ui_notification/ui_notification.py index eb419db426cd516da30f5f953b8a52850a470d79..bbf7218fb47e9f2be9d6c8b0ee09ffd21df5e838 100644 --- a/force_bdss/core_plugins/dummy/ui_notification/ui_notification.py +++ b/force_bdss/core_plugins/dummy/ui_notification/ui_notification.py @@ -1,3 +1,5 @@ +import errno +import logging from traits.api import Any, List from force_bdss.api import BaseNotificationListener @@ -5,17 +7,30 @@ import zmq class UINotification(BaseNotificationListener): + #: The ZMQ context. _context = Any() + + #: The pubsub socket. _pub_socket = Any() + + #: The synchronization socket to recover already sent information at a + #: later stage _rep_socket = Any() + + #: The cache of messages as they are sent out. _msg_cache = List() def deliver(self, model, message): try: data = self._rep_socket.recv(flags=zmq.NOBLOCK) - except zmq.ZMQError: - pass - else: + except zmq.ZMQError as e: + if e.errno == errno.EAGAIN: + data = None + else: + logging.error("Error while receiving data from " + "reply socket: {}".format(str(e))) + + if data and data[0:4] == "SYNC".encode("utf-8"): self._rep_socket.send_multipart(self._msg_cache) msg = "ACTION {}".format(message).encode("utf-8") diff --git a/utils/zmq_client.py b/utils/zmq_client.py index 03a2b44a3644a640ea5d1124d68f80ff760d8453..a78f368979c336eb1258812b83f8e138a5c24809 100644 --- a/utils/zmq_client.py +++ b/utils/zmq_client.py @@ -9,16 +9,12 @@ socket.connect("tcp://localhost:12345") socket.setsockopt(zmq.SUBSCRIBE, "".encode("utf-8")) send_socket = context.socket(zmq.REQ) send_socket.connect("tcp://localhost:12346") -send_socket.send("hello".encode("utf-8")) -while True: - try: - data = send_socket.recv_multipart(flags=zmq.NOBLOCK) - except zmq.ZMQError: - pass - else: - print("RECOVERING CACHE", data) - break +send_socket.send("SYNC".encode("utf-8")) +data = send_socket.recv_multipart() +for d in data: + topic, messagedata = d.split() + print("SYNCED ", topic, messagedata) while True: string = socket.recv()