hrpc/example/server.py

24 lines
621 B
Python
Raw Normal View History

2020-08-09 01:35:01 +00:00
"""Greeter server."""
2020-08-09 01:53:39 +00:00
from purerpc import Server
2020-08-09 01:35:01 +00:00
from greeter_grpc import GreeterServicer
from greeter_pb2 import HelloReply, HelloRequest
class Greeter(GreeterServicer):
async def SayHello(self, message):
2020-08-09 01:53:39 +00:00
return HelloReply(message=f"Hello, {message.name}")
2020-08-09 01:35:01 +00:00
async def SayHelloToMany(self, input_messages):
async for message in input_messages:
yield HelloReply(message=f"Hello, {message.name}")
2020-08-09 00:52:58 +00:00
if __name__ == "__main__":
2020-08-09 01:35:01 +00:00
server = Server(50055)
server.add_service(Greeter().service)
try:
server.serve(backend="trio")
except KeyboardInterrupt:
pass