New universal pubsub interface in zmq_socket.py. Needs more work.
This commit is contained in:
+8
-9
@@ -29,11 +29,11 @@ from air_modes.exceptions import *
|
||||
import zmq
|
||||
|
||||
class screen_printer(threading.Thread):
|
||||
def __init__(self, position, context, addr=None):
|
||||
def __init__(self, position, context, addr=None, port=None):
|
||||
threading.Thread.__init__(self)
|
||||
self._subscriber = context.socket(zmq.SUB)
|
||||
if addr is not None:
|
||||
self._subscriber.connect("tcp://%s" % addr)
|
||||
self._subscriber.connect("tcp://%s:%i" % (addr, port))
|
||||
else:
|
||||
self._subscriber.connect("inproc://modes-radio-pub")
|
||||
self._subscriber.setsockopt(zmq.SUBSCRIBE, "dl_data")
|
||||
@@ -45,7 +45,6 @@ class screen_printer(threading.Thread):
|
||||
self.start()
|
||||
|
||||
def run(self):
|
||||
queue_empty = False
|
||||
while not self.done.is_set():
|
||||
[address, msg] = self._subscriber.recv_multipart() #blocking
|
||||
try:
|
||||
@@ -55,7 +54,6 @@ class screen_printer(threading.Thread):
|
||||
|
||||
self._subscriber.close()
|
||||
self.finished.set()
|
||||
|
||||
|
||||
def main():
|
||||
my_position = None
|
||||
@@ -82,6 +80,7 @@ def main():
|
||||
#construct the radio
|
||||
context = zmq.Context(1)
|
||||
tb = air_modes.modes_radio(options, context)
|
||||
relay = air_modes.zmq_pubsub_iface(context, subaddr="inproc://modes-radio-pub", pubaddr=None)
|
||||
|
||||
if options.location is not None:
|
||||
reader = csv.reader([options.location], quoting=csv.QUOTE_NONNUMERIC)
|
||||
@@ -94,7 +93,8 @@ def main():
|
||||
|
||||
printer = None
|
||||
if options.no_print is not True:
|
||||
printer = screen_printer(my_position, context)
|
||||
relay.subscribe("dl_data", air_modes.output_print(my_position).output)
|
||||
#printer = screen_printer(my_position, context)
|
||||
|
||||
# if options.multiplayer is not None:
|
||||
# [fghost, fgport] = options.multiplayer.split(':')
|
||||
@@ -105,13 +105,12 @@ def main():
|
||||
# sbs1port = air_modes.output_sbs1(my_position, 30003)
|
||||
# tb.subscribe('dl_data', sbs1port.output)
|
||||
#updates.append(sbs1port.add_pending_conns)
|
||||
|
||||
tb.run()
|
||||
tb.cleanup()
|
||||
|
||||
if printer is not None:
|
||||
printer.done.set()
|
||||
printer.finished.wait(0.2)
|
||||
relay.shutdown.set()
|
||||
relay.finished.wait(0.2)
|
||||
|
||||
if options.kml is not None:
|
||||
sqldb.done = True
|
||||
#sqldb.join()
|
||||
|
||||
Reference in New Issue
Block a user