python 调用stream cancel()后如何处理grpc stream
python How to handle grpc stream after stream cancel() is called
我正在尝试编写一个 python 客户端来终止 gRPC 流
原型:
rpc Start (StartParameters) returns (stream Progress) {}
在客户端中,当我准备终止流时,我尝试调用 stream.cancel() 然后当我打印捕获的流的事件时,它不会打印事件。我看到异常
<_Rendezvous of RPC that terminated with:
status = StatusCode.CANCELLED
details = "Locally cancelled by application!"
debug_error_string = "None"
client.py
stream = self.stub.Start(params)
time.sleep(120)
stream.cancel()
for event in stream:
print(event)
有人可以帮我提供 python 代码来取消此流并打印流中的事件。
问题是您在实际开始迭代之前取消了流。尝试在另一个线程上异步取消 RPC。
stream = self.stub.Start(params)
def _cancel_after_a_while():
time.sleep(120)
stream.cancel()
cancellation_thread = threading.Thread(target=_cancel_after_a_while)
cancellation_thread.start()
for event in stream:
print(event)
我正在尝试编写一个 python 客户端来终止 gRPC 流
原型:
rpc Start (StartParameters) returns (stream Progress) {}
在客户端中,当我准备终止流时,我尝试调用 stream.cancel() 然后当我打印捕获的流的事件时,它不会打印事件。我看到异常
<_Rendezvous of RPC that terminated with:
status = StatusCode.CANCELLED
details = "Locally cancelled by application!"
debug_error_string = "None"
client.py
stream = self.stub.Start(params)
time.sleep(120)
stream.cancel()
for event in stream:
print(event)
有人可以帮我提供 python 代码来取消此流并打印流中的事件。
问题是您在实际开始迭代之前取消了流。尝试在另一个线程上异步取消 RPC。
stream = self.stub.Start(params)
def _cancel_after_a_while():
time.sleep(120)
stream.cancel()
cancellation_thread = threading.Thread(target=_cancel_after_a_while)
cancellation_thread.start()
for event in stream:
print(event)