【发布时间】:2017-12-06 19:53:28
【问题描述】:
我将我的 python gRPC 服务器部署到 Heroku,并且想知道如何使用本地 Python 客户端对其进行测试。
server.py
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
icp_pb2_grpc.add_MyServicer_to_server(MyServicer(), server)
server_port = os.environ.get('PORT', 50051)
server.add_insecure_port('[::]:'+ str(server_port))
server.start()
print("==== SERVER RUNNING =====")
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
client.py
def run():
# Is the channel url correct?
channel = grpc.insecure_channel('https://www.HEROKUURL.com:50051')
stub = my_grpc.MyStub(channel)
file = _get_file_content()
response = stub.Predict(icp_pb2.MyRequest(file_content=file))
print("received: " + response.results)
我正在使用我的计算机上的客户端,但没有收到来自服务器的任何响应。如果它在本地启动,我能够与服务器成功通信。我做错了什么?
【问题讨论】:
-
您有多确定 gRPC 与问题有关?您是否在 Heroku 环境中运行过普通的 HTTP 服务器并能够连接到它?
-
@NathanielManistaAtGoogle 可以肯定的是,我能够成功地与普通服务器通信。 gRPC 应用程序在本地也能完美运行。不是 gRPC 有问题,我只是不确定如何部署它并连接到服务器。
标签: python heroku deployment grpc