python grpc:设置每个grpc调用的超时

时间:2019-09-13 08:39:31

标签: grpc-python

是否可以使用python指定每次grpc调用的超时时间。 我收到回复的时间超过了1分钟。 如果要花费更长的时间,我希望api返回一些错误。我正在使用阻止grpc的呼叫。

1 个答案:

答案 0 :(得分:0)

您可以在gRPC Python的API reference中查找所需的信息。设置超时应该很简单:

channel = grpc.insecure_channel(...)
stub = ...(channel)
stub.AnRPC(request, timeout=5)  # 5 seconds timeout