hrpc/example/client.py

26 lines
594 B
Python
Raw Normal View History

2020-08-09 01:35:01 +00:00
"""Greeter client."""
import anyio
import purerpc
2020-08-09 01:53:39 +00:00
2020-08-09 01:35:01 +00:00
from greeter_grpc import GreeterStub
from greeter_pb2 import HelloReply, HelloRequest
async def gen():
for i in range(5):
yield HelloRequest(name=str(i))
async def main():
async with purerpc.insecure_channel("localhost", 50055) as channel:
stub = GreeterStub(channel)
reply = await stub.SayHello(HelloRequest(name="World"))
print(reply.message)
async for reply in stub.SayHelloToMany(gen()):
print(reply.message)
2020-08-09 00:52:58 +00:00
if __name__ == "__main__":
2020-08-09 01:35:01 +00:00
anyio.run(main, backend="trio")