Python异步grpc客户端流句柄

2024-05-19 06:23:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python async GRPC的新手,我提出了以下方法来处理异步流:

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()

然而,一旦蒸汽中没有结果,则循环将结束,然后蒸汽将关闭,程序退出。我怎样才能保持溪流畅通

在Java中,我可以使用倒计时闩锁来保持异步grpc流打开


Tags: 方法streamgetasyncgrpcaschannelresp

热门问题