Clean up logic in zmq_socket and don't repeat code

This commit is contained in:
Nick Foster 2013-06-08 16:06:16 -04:00
parent 51cb2bdf46
commit d2a6f40bbd

View File

@ -85,7 +85,10 @@ class zmq_pubsub_iface(threading.Thread):
return self._pubsub[key] return self._pubsub[key]
def run(self): def run(self):
while not self.shutdown.is_set(): done = False
while not self.shutdown.is_set() and not done:
if self.shutdown.is_set():
done = True
#send #send
while not self._queue.empty(): while not self._queue.empty():
self._pubsocket.send_multipart(self._queue.get()) self._pubsocket.send_multipart(self._queue.get())
@ -98,11 +101,8 @@ class zmq_pubsub_iface(threading.Thread):
self._pubsub[address] = msg self._pubsub[address] = msg
socks = dict(self._poller.poll(timeout=0)) socks = dict(self._poller.poll(timeout=0))
#snooze #snooze
time.sleep(0.1) if not done:
time.sleep(0.1)
#one more send loop to clean up on shutdown (can probably express this better above)
while not self._queue.empty():
self._pubsocket.send_multipart(self._queue.get())
self._subsocket.close() self._subsocket.close()
self._pubsocket.close() self._pubsocket.close()
@ -133,8 +133,8 @@ if __name__ == "__main__":
sock2["data1"] = "PARDNER" sock2["data1"] = "PARDNER"
time.sleep(0.1) time.sleep(0.1)
time.sleep(0.1)
sock1.close() sock1.close()
sock2.close() sock2.close()
sock3.close() sock3.close()