def handle_connection(self, cl_socket): """ Handle socket connection. :param cl_socket: :return: """ service = None while True: cmd, msg = retrieve_msg(cl_socket) if cmd == b'I': resp = service.predict(msg) cl_socket.send(resp) elif cmd == b'L': service, result, code = self.load_model(msg) resp = bytearray() resp += create_load_model_response(code, result) cl_socket.send(resp) if code != 200: raise RuntimeError("{} - {}".format(code, result)) else: raise ValueError("Received unknown command: {}".format(cmd)) if service is not None and service.context is not None and service.context.metrics is not None: emit_metrics(service.context.metrics.store)
def handle_connection(self, cl_socket): """ Handle socket connection. :param cl_socket: :return: """ logging.basicConfig(stream=sys.stdout, format="%(message)s", level=logging.INFO) cl_socket.setblocking(True) while True: cmd, msg = retrieve_msg(cl_socket) if cmd == b'I': resp = self.service.predict(msg) cl_socket.send(resp) elif cmd == b'L': result, code = self.load_model(msg) resp = bytearray() resp += create_load_model_response(code, result) cl_socket.send(resp) self._remap_io() if code != 200: raise RuntimeError("{} - {}".format(code, result)) else: raise ValueError("Received unknown command: {}".format(cmd)) if self.service is not None and self.service.context is not None \ and self.service.context.metrics is not None: emit_metrics(self.service.context.metrics.store)
def handle_connection(self, cl_socket): """ Handle socket connection. :param cl_socket: :return: """ service = None while True: cmd, msg = retrieve_msg(cl_socket) if cmd == b'I': resp = service.predict(msg) cl_socket.send(resp) elif cmd == b'L': service, result, code = self.load_model(msg) resp = bytearray() resp += create_load_model_response(code, result) cl_socket.send(resp) else: raise ValueError("Received unknown command: {}".format(cmd))
def test_create_load_model_response(self): msg = codec.create_load_model_response(200, "model_loaded") assert msg == b'\x00\x00\x00\xc8\x00\x00\x00\x0cmodel_loaded\xff\xff\xff\xff'