14 """The Python AsyncIO example of utilizing Channelz feature."""
23 helloworld_pb2, helloworld_pb2_grpc = grpc.protos_and_services(
29 _LOGGER = logging.getLogger(__name__)
30 _LOGGER.setLevel(logging.INFO)
32 _RANDOM_FAILURE_RATE = 0.3
41 self, request: helloworld_pb2.HelloRequest,
44 context.abort(grpc.StatusCode.UNAVAILABLE,
45 'Randomly injected failure.')
50 server = grpc.aio.server()
55 channelz.add_channelz_servicer(server)
57 server.add_insecure_port(addr)
62 parser = argparse.ArgumentParser()
63 parser.add_argument(
'--addr',
67 help=
'the address to listen on')
73 help=
'a float indicates the percentage of failed message injections')
74 args = parser.parse_args()
76 server =
create_server(addr=args.addr, failure_rate=args.failure_rate)
78 await server.wait_for_termination()
81 if __name__ ==
'__main__':
82 logging.basicConfig(level=logging.INFO)
83 asyncio.get_event_loop().run_until_complete(
main())