Example #1
0
def main():
    chanel = grpc.insecure_channel('localhost:8080')
    # 使用Stub
    client = pi_pb2_grpc.PiCalculatorStub(chanel)
    # 调用
    for i in range(100000000000):
        client.Calc(pi_pb2.PiRequest(n=i))
Example #2
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    pool = futures.ThreadPoolExecutor(max_workers=10)
    results = []
    for i in range(1, 1000):
        results.append((i, pool.submit(pi, client, i)))
    pool.shutdown()
Example #3
0
def main():
    channel = grpc.insecure_channel('localhost:8080', chan_ops)
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(10):
        try:
            res = client.Calc(pi_pb2.PiRequest(n=i))
            print "pi(%d) =" % i, res.value
        except grpc.RpcError as e:
            print e.code(), e.details()
Example #4
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(0, 1000):
        try:
            print('pi(%d) =' % i,
                  client.Calc(pi_pb2.PiRequest(n=i), timeout=5).value)
        except grpc.RpcError as e:
            print(e.code())
            print(e.details())
Example #5
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    # client 对象是线程安全的
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    # 客户端使用线程池执行
    pool = futures.ThreadPoolExecutor(max_workers=4)
    results = []
    for i in range(1000):
        results.append((i, pool.submit(pi, client, i)))
    # 等待所有任务执行完毕
    pool.shutdown()
Example #6
0
def main():
    # channel = grpc.insecure_channel('localhost:8080')

    chan_ops = [('grpc.default_compression_algorithm',
                 CompressionAlgorithm.gzip),
                ('grpc.grpc.default_compression_level', CompressionLevel.high)]
    channel = grpc.insecure_channel('localhost:8080', chan_ops)

    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(2):
        try:
            print "pi(%d) =" % i, client.Calc(pi_pb2.PiRequest(n=i),
                                              timeout=5).value
        except grpc.RpcError as e:
            # print e.code(), e.details()
            print e.code(), e.initial_metadata()
Example #7
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    response_iterator = client.Calc(generate_request())
    for response in response_iterator:
        print("pi(%d) =" % response.n, response.value)
Example #8
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    for i in range(1, 1000):
        print "pi(%d) = " % i, client.Calc(pi_pb2.PiRequest(n=i)).value
Example #9
0
def main():
    channel = grpc.insecure_channel('localhost:8080')
    client = pi_pb2_grpc.PiCalculatorStub(channel)
    response_iterator = client.Calc(generate_request())