def run(self): self.context = pyzmq.Context(self.gevent) self._create_frontend() self.frontend.bind(self.frontend_address) self._create_backend() self.backend.bind(self.backend_address) print("%s connecting %s to %s" % (self.__class__.__name__, self.frontend_address, self.backend_address)) pyzmq.device(self.device_type, self.frontend, self.backend, self.gevent)
def json_sub_logger(ports): context = pyzmq.Context() socket = context.socket(pyzmq.SUB) for port in ports: print("Log subscribed to port %s" % port) socket.connect("tcp://localhost:%s" % port) # topicfilter blank to get all messages socket.setsockopt(pyzmq.SUBSCRIBE, "") while True: data = socket.recv_json() pprint.pprint(data)
def __init__(self, address, context=pyzmq.Context(), single=False, worker_id='Subscriber', json=True, topic='', *args, **kwargs): self.topic = topic super(Subscriber, self).__init__(address=address, context=context, single=single, worker_id=worker_id, json=json, *args, **kwargs)
def _bootstrap(self): root_found = False for runner in self.runners: if runner.rank == 0: root_found = True break if not root_found: raise ValueError("No root node.") port = "5556" context = zmq.Context() socket = context.socket(zmq.PAIR) while not socket.bind("tcp://*:%s" % port): port = port + 1 socket.send(b"Server message to client3") msg = socket.recv()
def _init_process(self): self.context = pyzmq.Context() super(Process, self)._connect_socket()