def receive_batches(): try: while (True): while (True): try: rrec = self.sub.recv() break except nnpy.NNError as e: if (e.error_no == nnpy.ETIMEDOUT): for rec in self.receivers: if (len(rec.expecting_batches) > 0): print( "Timeout, receiving batches - despite expecting %d - requesting missing batches" % (len(rec.expecting_batches))) rec.request_batch( len(rec.expecting_batches)) continue raise e rec = msg.Record() rec.ParseFromString(rrec) accepted = False for receiver in self.receivers: if (receiver.accept(rec)): accepted = True break if (not accepted): self.ignored_count += 1 finally: print("Finished receiving batches")
nbytes = 0 okcount = 0 print("Working ...") while(True): while True: try: recd = sub.recv() break except nnpy.NNError as e: if (e.error_no==nnpy.ETIMEDOUT): print("Nothing to do") else: print("Exception: %r - %d" % (e, e.error_no)) #print("Recv %d bytes" % (len(recd))) nbytes += len(recd) rec = msg.Record() rec.ParseFromString(recd) i+=1 if (rec.error_code==msg.OK): try: image = accimage.Image(bytes=rec.data) img_ndarr = img_transforms(image) rec.route_id=0 rec.data = img_ndarr.tobytes() pub.send(rec.SerializeToString()) okcount+=1 except: import traceback traceback.print_exc() rec.route_id = 0 rec.data = b""