def run(self): print('Start data provider {}-{}'.format(self.pipename, self.identity)) setproctitle('data provider {}-{}'.format(self.pipename, self.identity)) ctx = zmq.Context() socket = ctx.socket(zmq.DEALER) socket.setsockopt(zmq.IDENTITY, self.identity) socket.set_hwm(self.hwm) socket.connect(self.pipename) while True: dp = loads(socket.recv(copy=False).bytes) dp = self.map_func(dp) socket.send(dumps(dp), copy=False)
def _test_round_trip(self, obj): dumped = dumps(obj, self.FMT) # dumps / loads self.assertEqual(obj, loads(dumped, self.FMT)) buf = io.BytesIO() dump(obj, buf, self.FMT) # dump / dumps self.assertEqual(dumped, buf.getvalue()) buf.seek(0) # dump / load self.assertEqual(obj, load(buf, self.FMT))
def _send(self, dp): # round-robin assignment worker = next(self._iter_worker) msg = [worker, dumps(dp)] self.socket.send_multipart(msg, copy=False)
def test_response_bytes(self): obj = "here I am" self.assertIsInstance(dumps(obj, self.FMT), bytes)
def test_response_bytes(self): obj = 'here I am' self.assertIsInstance(dumps(obj, self.FMT), bytes)