thrift timeout for long run call: thrift.transport

2019-09-17 16:05发布

I've build some a rpc service using thrift. It may run long time (minutes to hours) for each call. I've set the thrift timeout to 2 days.

transport = TSocket.TSocket(self.__host, self.__port)
transport.setTimeout(2 * 24 * 60 * 60 * 1000)

But the thrift always closes connection after about 600s, with the following exception:

thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

Is there's any other timeout should i set? (python, thrift server: windows; client: ubuntu)

1条回答
混吃等死
2楼-- · 2019-09-17 16:36

The Thrift Transport connection is being disconnected. This could be due to network issues or remote service restart or time out issues. Whenever any call is made after a disconnect this results in TTransportException. This problem can be solved by reconnecting to the remote service. Try using this, invoking it before making a remote service call.

def repoen_transport():
    try:
        if not transport.isOpen():
            transport.open()
    except Exception, msg:
        print >> sys.stderr.write("Error reopening transport {}".format(msg))
查看更多
登录 后发表回答