{"id":204315,"date":"2020-11-11T09:30:00","date_gmt":"2020-11-11T01:30:00","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=204315"},"modified":"2020-11-01T17:44:05","modified_gmt":"2020-11-01T09:44:05","slug":"python-grpc-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-grpc-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdPython grpc\u8d85\u65f6\u673a\u5236"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Python grpc\u8d85\u65f6\u673a\u5236\u4ee3\u7801\u793a\u4f8b,\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u5de5\u4f5c\u4e2d\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u4e0a\u6e38\u670d\u52a1\u901a\u8fc7grpc\u8c03\u7528\u4e0b\u6e38\u670d\u52a1\uff0c\u4f46\u662f\u7531\u4e8e\u4e0b\u6e38\u670d\u52a1\u8d1f\u8f7d\u592a\u9ad8\u5bfc\u81f4\u4e0a\u6e38\u670d\u52a1\u7684\u8c03\u7528\u4f1a\u968f\u673a\u51fa\u73b0\u8d85\u65f6\u7684\u60c5\u51b5\uff0c\u4f46\u662f\u6709\u4e00\u70b9\u4e0d\u592a\u660e\u786e\uff1a\u8d85\u65f6\u4e4b\u540e\uff0c\u4e0b\u6e38\u670d\u52a1\u8fd8\u4f1a\u7ee7\u7eed\u8fdb\u884c\u8ba1\u7b97\u4e48\uff1f<\/p>\n \u4e8e\u662f\u81ea\u5df1\u5199\u4e86\u4e00\u4e2adamon\u8bd5\u4e86\u4e00\u4e0b\uff1a<\/p>\n client\uff1a<\/strong><\/span><\/div>\n \r\n# Copyright 2015 gRPC authors.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the \"License\");\r\n# you may not use this file except in compliance with the License.\r\n# You may obtain a copy of the License at\r\n#\r\n# http:\/\/www.apache.org\/licenses\/LICENSE-2.0\r\n#\r\n# Unless required by applicable law or agreed to in writing, software\r\n# distributed under the License is distributed on an \"AS IS\" BASIS,\r\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n# See the License for the specific language governing permissions and\r\n# limitations under the License.\r\n\"\"\"The Python implementation of the GRPC helloworld.Greeter client.\"\"\"\r\n \r\nfrom __future__ import print_function\r\nimport logging\r\n \r\nimport grpc\r\n \r\nimport helloworld_pb2\r\nimport helloworld_pb2_grpc\r\n \r\n \r\ndef run():\r\n # NOTE(gRPC Python Team): .close() is possible on a channel and should be\r\n # used in circumstances in which the with statement does not fit the needs\r\n # of the code.\r\n with grpc.insecure_channel('localhost:50051') as channel:\r\n stub = helloworld_pb2_grpc.GreeterStub(channel)\r\n response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), timeout=30)\r\n print(\"Greeter client received: \" + response.message)\r\n \r\n \r\nif __name__ == '__main__':\r\n logging.basicConfig()\r\n run()<\/pre>\n |