def handle_connection(self, cl_socket): """ Handle socket connection. :param cl_socket: :return: """ service = None while True: if BENCHMARK: pr.disable() pr.dump_stats('/tmp/tsPythonProfile.prof') cmd, msg = retrieve_msg(cl_socket) if BENCHMARK: pr.enable() if cmd == b'I': resp = service.predict(msg) cl_socket.sendall(resp) elif cmd == b'L': service, result, code = self.load_model(msg) resp = bytearray() resp += create_load_model_response(code, result) cl_socket.sendall(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 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'