python grpc超时机制有些疑问

来源:45-5 python下实现重试机制

城中城

2022-07-26

这里
https://www.yuque.com/bobby-zpcyu/fgmqcv/enncpo
我看完这节课 感觉有点问题 ( 可能后面几节课看完就迎刃而解 )
但是还是忍不住想问一下

python下超时重试机制
我加了个 打印 没出现重试这个机制啊

当你 设置了 超时参数后

    with grpc.insecure_channel('localhost:50051') as channel:
        intercept_channel = grpc.intercept_channel(channel, default_value_interceptor, retry_interceptor)
        stub = helloworld_pb2_grpc.GreeterStub(intercept_channel)
        response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), timeout=1)

没等你重试 它就报错了 然后就结束进程了
导致你 重试根本没有任何用处
第二个 问题:
intercept_unary_stream 函数有什么用吗 起到了什么用处
看了过去 只看到 intercept_unary_unary 运行到了

写回答

1回答

bobby

2022-07-29

intercept_unary_stream 是用于对stream接口进行拦截的, 

没等你重试 它就报错了 然后就结束进程了 具体报错信息是什么

0
2
城中城
具体报错信息是什么 就是如你课程上的 超时 报错 超时报错 是没有问题的 我这里说的是重试机制 有问题 为什么说重试 机制有问题呢 看下面代码 我在 retry.py文件中 加上一个打印 while True: try: print("执行到这里了") response = continuation(client_call_details, request) print("获取到所需要的信息了") return response except RpcError as e: if e.code() not in self.retry_codes: # 如果不是 我们选择的错误中的一种 则 报错 raise e if retry_count >= self.max_retries: # 如果超出重试次数 则报错 raise e retry_count += 1 # 次数 +1 time.sleep(self._next_retry_timeout_seconds()) # 等待的时间 执行一下 就很明显的看出来 没有做任何重试 只要超时了 你指定的时间后 就一定会结束 而不会重试
2022-07-29
共2条回复

Go+Python打造电商系统 自研微服务框架 抓紧高薪机遇

快速转型Go工程师,成为具备双语言后端能力的开发者

508 学习 · 530 问题

查看课程