Add channel_ready helper function

pull/21885/head
Lidi Zheng 5 years ago
parent ffb41a2368
commit 6a330edf74
  1. 4
      src/python/grpcio/grpc/experimental/aio/__init__.py
  2. 12
      src/python/grpcio/grpc/experimental/aio/_channel.py
  3. 1
      src/python/grpcio_tests/tests_aio/tests.json

@ -26,7 +26,7 @@ from grpc._cython.cygrpc import EOF, AbortError, init_grpc_aio
from ._base_call import Call, RpcContext, UnaryStreamCall, UnaryUnaryCall
from ._call import AioRpcError
from ._channel import Channel, UnaryUnaryMultiCallable
from ._channel import Channel, UnaryUnaryMultiCallable, channel_ready
from ._interceptor import (ClientCallDetails, InterceptedUnaryUnaryCall,
UnaryUnaryClientInterceptor)
from ._server import Server, server
@ -88,4 +88,4 @@ __all__ = ('AioRpcError', 'RpcContext', 'Call', 'UnaryUnaryCall',
'UnaryUnaryMultiCallable', 'ClientCallDetails',
'UnaryUnaryClientInterceptor', 'InterceptedUnaryUnaryCall',
'insecure_channel', 'server', 'Server', 'EOF', 'secure_channel',
'AbortError')
'AbortError', 'channel_ready')

@ -512,3 +512,15 @@ class Channel:
request_serializer,
response_deserializer, None,
self._loop)
async def channel_ready(channel: Channel) -> None:
"""Creates a coroutine that ends when a Channel is ready.
Args:
channel: A grpc.aio.Channel object.
"""
state = channel.get_state(try_to_connect=True)
while state != grpc.ChannelConnectivity.READY:
await channel.wait_for_state_change(state)
state = channel.get_state(try_to_connect=True)

@ -9,6 +9,7 @@
"unit.call_test.TestUnaryStreamCall",
"unit.call_test.TestUnaryUnaryCall",
"unit.channel_argument_test.TestChannelArgument",
"unit.channel_ready_test.TestChannelReady",
"unit.channel_test.TestChannel",
"unit.close_channel_test.TestCloseChannel",
"unit.close_channel_test.TestOngoingCalls",

Loading…
Cancel
Save