Example #1
0
 def process_response(call_future):
     try:
         list_result = str_2_list_by_json(call_future.result().data)
         results.extend(list_result)
         tags.append(1)
         logging.info("--------------end_call_grpc-------------")
     except:
         logging.error("--------------fail_call_grpc-------------")
Example #2
0
    def SendData(self, request, context):
        logging.info("start_get_data, url: {}".format( request.name) )
        start = time.time()
        code, audios_data = inference(request.name)
        end = time.time()

        if code == 0:
            logging.info("success_get_data, time: {}s, data_size: {}, url: {}".format( (end - start), len(audios_data), request.name) )
        else:
            logging.error("fail_get_data, time: {}s, data_size: {}, url: {}".format( (end - start), len(audios_data), request.name) )

        return call_ant_pb2.AntReply(code=code, data=audios_data)
Example #3
0
    def SendData(self, request, context):
        # logging.info("start_get_data, url: {}".format(request.name) )
        start = time.time()
        code, data = infer(request.image)
        end = time.time()

        if code == 200:
            logging.info(
                "success_get_data, time: {}s, size: {}, url: {}".format(
                    (end - start), len(data), 'test'))
        else:
            logging.error("fail_get_data, time: {}s, size: {}, url: {}".format(
                (end - start), len(data), 'test'))

        return PiReply(code=code, data=data)
Example #4
0
def get_res_by_grpc(grpc_host, text):

    logging.info("start_call_grpc, grpc_host: {}, url: {}".format( grpc_host, text ) )

    start = time.time()
    channel = grpc.insecure_channel(grpc_host)
    stub = call_ant_pb2_grpc.GreeterStub(channel)
    response = stub.SendData(call_ant_pb2.AntRequest(name=text))
    end = time.time()

    if response.code == 200:
        logging.info("success_data_by_grpc, time: {}s, size: {}, url: {}".format( (end-start), len(response.data), text) )
    else:
        logging.error("fail_call_grpc, time: {}s, data_size: {}, url: {}".format( (end-start), len(response.data), text) )

    return response.data
Example #5
0
def get_sort_by_grpc(grpc_host, resp_data, list_url):

    logging.info("start_call_grpc, grpc_host: {}, url: {}".format( grpc_host, list_url ) )
    start = time.time()
    channel = grpc.insecure_channel(grpc_host)
    stub = call_ant_pb2_grpc.GreeterStub(channel)
    response = stub.SendData(call_ant_pb2.AntRequest(name=resp_data))
    end = time.time()
    list_result = str_2_list_by_json(response.data)

    if response.code == 200:
        logging.info("success_call_grpc, time: {}s, data_size: {}, url: {}".format( (end-start), len(response.data), list_url) )
    else:
        logging.error("fail_call_grpc, time: {}s, data_size: {}, url: {}".format( (end-start), len(response.data), list_url) )

    return list_result
Example #6
0
def get_res_by_grpc(grpc_host, img_64):
    logging.info("start_call_grpc, grpc_host: {}, url: {}".format(
        grpc_host, 'test'))

    start = time.time()
    channel = grpc.insecure_channel(grpc_host)
    stub = PiServiceStub(channel)
    response = stub.SendData(PiRequest(image=img_64))
    end = time.time()

    if response.code == 200:
        logging.info("success_call_grpc, time: {}s, size: {}, url: {}".format(
            (end - start), len(response.data), 'text'))
    else:
        logging.error("fail_call_grpc, time: {}s, size: {}, url: {}".format(
            (end - start), len(response.data), 'text'))

    return response.code, response.data
Example #7
0
def get_sort_by_grpc_async(grpc_host, resp_data, list_url, results = [], tags=[]):

    def process_response(call_future):
        try:
            list_result = str_2_list_by_json(call_future.result().data)
            results.extend(list_result)
            tags.append(1)
            logging.info("--------------end_call_grpc-------------")
        except:
            logging.error("--------------fail_call_grpc-------------")

    ret = True
    try:
        logging.info("start_call_grpc, grpc_host: {}s, url: {}".format( grpc_host, list_url) )
        channel = grpc.insecure_channel(grpc_host)
        stub = call_ant_pb2_grpc.GreeterStub(channel)
        call_future = stub.SendData.future(call_ant_pb2.AntRequest(name=resp_data))
        call_future.add_done_callback(process_response)
    except:
        tags.append(1)
        logging.error("-----fail_get_sort_by_grpc, host: {}".format( grpc_host ) )
        ret = False

    return ret