如何在Thrift Python客户端中设置RPC超时时间?

6
我正在使用Thrift编写Python客户端,但是我找不到任何可用的选项来设置RPC超时时间。
以下是我的客户端代码:
socket = TSocket.TSocket(address, port)
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
server = Client.Client(protocol)
transport.open()
1个回答

13
你可以使用socket.setTimeout()方法。
from thrift.transport.THttpClient import THttpClient
socket = THttpClient(server_url)
socket.setTimeout(SERVICE_TIMEOUT_IN_mS)
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)

仅供参考,settimeout确实会影响send、recv和connect操作,并且没有办法分离这些超时。https://docs.python.org/2/library/socket.html#socket.socket.settimeout - Emmanuel Courreges
1
请注意,TSocket.setTimeout接受毫秒为单位,而socket.settimeout接受以秒为单位的浮点数! - Emmanuel Courreges

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接