From 2e561bbed997495f543e6ec313386c8e95c58cc0 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Fri, 28 Apr 2017 23:11:30 +0200 Subject: [PATCH] a little experiment with zmq polling --- screenless/bureau/bureau.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 5d662c5..3d701fb 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -308,12 +308,21 @@ class Bureau(object): # register commands and api methods self._publish_methods() + poller = zmq.Poller() + poller.register(self._recv, zmq.POLLIN) + while True: try: - msg = self._recv.recv_string(flags=zmq.NOBLOCK) - except zmq.ZMQError: - time.sleep(0.05) # don't waste CPU - continue + msgs = dict(poller.poll(500)) + if msgs: + if msgs.get(self._recv) == zmq.POLLIN: + msg = self._recv.recv_string(flags=zmq.NOBLOCK) + else: + continue + # msg = self._recv.recv_string(flags=zmq.NOBLOCK) + #except zmq.ZMQError: + # time.sleep(0.05) # don't waste CPU + # continue try: self.log.debug("got message:" + msg) dot = msg.find(".")