I am a newbie to python async GRPC and I came up with this to handle an async stream:
async with grpc.aio.insecure_channel(target='localhost:6565', options=CHANNEL_OPTIONS) as channel:
stub = get_results_grpc.ResultServiceStub(channel)
stream = stub.GetResults(get_results_pb2.PositionsRequest(name=["test"]), timeout=10, metadata=metadata)
try:
async for resp in stream.__aiter__():
print(resp)
except grpc.RpcError as e:
print(e)
await asyncio.sleep(10)
stream.cancel()
However, once there is no result on in the steam, then loop will finish and then both the steam will be closed and the program exits. How could I keep the stream open ?
In Java, I could use a countdownLatch to keep async grpc stream open.