def rangeSquare(self, request, context): print(request.message) for i in range(int(request.message + 1)): yield Message(message=i**2)
#!/usr/bin/env python import grpc from data_pb2_grpc import SquareServiceStub from data_pb2 import Message url = "localhost:5000" conn = grpc.insecure_channel(url) client = SquareServiceStub(channel=conn) result = client.square(Message(message=12.3)) print(result)
#!/usr/bin/env python import grpc from data_pb2_grpc import SquareServiceStub from data_pb2 import Message url = "localhost:5000" conn = grpc.insecure_channel(url) client = SquareServiceStub(channel=conn) result = client.sumSquare(Message(message=i) for i in range(12)) print(result)
async def query(): async with insecure_channel(url) as conn: client = SquareServiceStub(channel=conn) async for response in client.streamrangeSquare( AsyncIterWrapper(Message(message=i) for i in range(12))): print(response.message)
async def query(): async with insecure_channel(url) as conn: client = SquareServiceStub(channel=conn) async for response in client.rangeSquare(Message(message=12)): print(response.message)
def sumSquare(self, request_iterator, context): result = 0 for i in request_iterator: result += i.message**2 return Message(message=result)
#!/usr/bin/env python import grpc from data_pb2_grpc import SquareServiceStub from data_pb2 import Message url = "localhost:5000" conn = grpc.insecure_channel(url) client = SquareServiceStub(channel=conn) for result in client.streamrangeSquare(Message(message=i) for i in range(12)): print(result)
async def query(): async with insecure_channel(url) as conn: client = SquareServiceStub(channel=conn) result = await client.square(Message(message=12.3)) print(result)
#!/usr/bin/env python import grpc from data_pb2_grpc import SquareServiceStub from data_pb2 import Message url = "localhost:5000" conn = grpc.insecure_channel(url) client = SquareServiceStub(channel=conn) for i in client.rangeSquare(Message(message=12)): print(i.message)
def streamrangeSquare(self, request_iterator, context): result = [] for i in request_iterator: result.append(i.message**2) for j in result: yield Message(message=j)
def square(self, request, context): return Message(message=request.message**2)
def streamrangeSquare(self, request_iterator, context): for i in request_iterator: yield Message(message=i.message**2)
async def query(): async with insecure_channel(url) as conn: client = SquareServiceStub(channel=conn) response = await client.sumSquare( AsyncIterWrapper(Message(message=i) for i in range(12))) print(response.message)
def square(self, request, context): f = Executor.submit(square, request.message) futures.as_completed(f) result = f.result() return Message(message=result)