Пример #1
0
def run():
    channel = grpc.insecure_channel('localhost:50051')
    stub = test_pb2_grpc.GreeterStub(channel)
    duration = 10
    end = time.time() + duration
    msgs = 0
    data = b'b' * (1 << 20)
    while time.time() < end:
        response = stub.SendData(test_pb2.Request(name=data))
        msgs += 1

    print('Received {} messages in {} second(s).'.format(msgs, duration))
def run():
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = test_pb2_grpc.GreeterStub(channel)

        response = stub.SayHello(test_pb2.HelloRequest(name='nujnus'))
        print("Greeter client received: " + response.message)

        response = stub.SayHelloAgain(test_pb2.HelloRequest(name='dream'))
#                        SayHelloAgain
        print("Greeter client received: " + response.message)

    print("Greeter client received: " + response.message)
Пример #3
0
def init():
    global client
    conn = grpc.insecure_channel(_HOST + ':' + _PORT)
    client = test_pb2_grpc.GreeterStub(channel=conn)
Пример #4
0

if __name__ == '__main__':

    print(generate_route())

    channel = grpc.insecure_channel('localhost:50051')
    my_channel_ready_future = grpc.channel_ready_future(channel)
    #<do some other stuff>
    try:
        my_channel_ready_future.result(timeout=10)  #秒
    except grpc.FutureTimeoutError:
        # <handle channel-did-not-connect>成功
        print('失败')
    else:
        print('成功')  # <make use of connected channel>
        stub = test_pb2_grpc.GreeterStub(channel)

        t_quque = threading.Thread(target=generate_route_queue_thread,
                                   args=(q, ))
        t_quque.start()
        responses = stub.Subscribe(generate_route_queue(q))
        #consume_route(responses)
        #t = threading.Thread(target=consume_route, args = (responses,))
        #t.start()
        print('eeeeeeeeee')

        #stop_thread(t)
        t_quque.join()
        #t.join()