国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Python grpc超時機制代碼示例

瀏覽:6日期:2022-07-11 11:34:45

工作中遇到一個問題,上游服務通過grpc調用下游服務,但是由于下游服務負載太高導致上游服務的調用會隨機出現超時的情況,但是有一點不太明確:超時之后,下游服務還會繼續進行計算么?

于是自己寫了一個damon試了一下:

client:

# Copyright 2015 gRPC authors.## Licensed under the Apache License, Version 2.0 (the 'License');# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an 'AS IS' BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.'''The Python implementation of the GRPC helloworld.Greeter client.'''from __future__ import print_functionimport loggingimport grpcimport helloworld_pb2import helloworld_pb2_grpcdef run(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel(’localhost:50051’) as channel: stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name=’you’), timeout=30) print('Greeter client received: ' + response.message)if __name__ == ’__main__’: logging.basicConfig() run()

server:

# Copyright 2015 gRPC authors.## Licensed under the Apache License, Version 2.0 (the 'License');# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an 'AS IS' BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.'''The Python implementation of the GRPC helloworld.Greeter server.'''from concurrent import futuresimport timeimport loggingimport grpcimport helloworld_pb2import helloworld_pb2_grpc_ONE_DAY_IN_SECONDS = 60 * 60 * 24class Greeter(helloworld_pb2_grpc.GreeterServicer): def SayHello(self, request, context): count = 0 while count < 10: print(’time:%s’ % (time.time())) time.sleep(5) return helloworld_pb2.HelloReply(message=’Hello, %s!’ % request.name)def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) server.add_insecure_port(’[::]:50051’) server.start() try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)if __name__ == ’__main__’: logging.basicConfig() serve()

這兩個例子就是在grpc官方提供的python例子上做了一下小的改動,得到的結果是:當client超時報錯退出之后,server還是會繼續進行計算,直到結束,那如果是這樣的話,超時的機制對于server來說是沒有作用的,即使client已經不再等待這個結果了,但是server還是會繼續計算,浪費server的資源。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 欧美人成在线视频 | 亚洲美女视频在线 | 国产日韩欧美久久久 | 女人张开腿让男人捅视频 | 久久久久久久免费 | 久久99国产亚洲高清观看首页 | 国产免费影院 | 久久精品男人的天堂 | 欧美精品hdvdeosex4k | 国产一区二区三区在线免费 | 国产东北色老头老太性视频 | 欧美午夜在线观看理论片 | 日本红怡院在线 | 在线久草| 一本一道久久综合狠狠老 | 精品三级在线观看 | 97精品久久久久中文字幕 | 国产成人看片免费视频观看 | 91久久青草精品38国产 | 亚洲精品成人7777在线观看 | 中文字幕乱码中文乱码51精品 | 亚洲网站在线播放 | 国产亚洲精品久久久久久午夜 | 久久久久欧美精品观看 | 欧美男人操女人 | 人操人碰| 久久久久久久99视频 | 最新国产三级在线不卡视频 | 久久久久国产一级毛片高清片 | 中文字幕在线日韩 | 亚洲精品tv久久久久 | 久草免费资源视频 | 国产午夜精品理论片免费观看 | 久久精品在线观看 | 精品成人免费视频 | 久久女同互慰一区二区三区 | 一本色道久久综合网 | 国产一区二区精品久 | 欧美国产精品亚洲精品第一区 | 免费观看一级欧美在线视频 | 国产成人在线播放视频 |