【发布时间】:2019-10-14 17:51:50
【问题描述】:
无法使来自服务器端的 grpc 连接超时。客户端可能会建立连接但保持保持/睡眠状态,这会导致 grpc 服务器连接挂起。服务器端有没有办法在一定时间后断开连接或设置超时?
我们尝试从客户端断开连接,但无法从服务器端断开连接。在此链接Problem with gRPC setup. Getting an intermittent RPC unavailable error 中,Angad 表示可以但无法在 python 中定义这些参数。
我的代码sn-p:
def serve():
server = grpc.server(thread_pool=futures.ThreadPoolExecutor(max_workers=2), maximum_concurrent_rpcs=None, options=(('grpc.so_reuseport', 1),('grpc.GRPC_ARG_KEEPALIVE_TIME_MS', 1000)))
stt_pb2_grpc.add_ListenerServicer_to_server(Listener(), server)
server.add_insecure_port("localhost:50051")
print("Server starting in port "+str(50051))
server.start()
try:
while True:
time.sleep(60 * 60 * 24)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
serve()
我希望在 python 中连接也应该从 grpc 服务器端超时。
【问题讨论】:
标签: python-multithreading grpc-python