为 xmlrpclib.ServerProxy 设置超时 [英] Set timeout for xmlrpclib.ServerProxy
本文介绍了为 xmlrpclib.ServerProxy 设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 xmlrpclib.ServerProxy 对远程服务器进行 RPC 调用.如果没有到服务器的网络连接,它需要默认的 10 秒将 socket.gaierror 返回到我的程序.
I am using xmlrpclib.ServerProxy to make RPC calls to a remote server. If there is not a network connection to the server it takes the default 10 seconds to return a socket.gaierror to my program.
在没有网络连接的情况下进行开发或远程服务器关闭时,这很烦人.有没有办法更新我的 ServerProxy 对象的超时时间?
This is annoying when doing development without a network connection, or if the remote server is down. Is there a way to update the timeout on my ServerProxy object?
我看不到访问套接字以更新它的明确方法.
I can't see a clear way to get access to the socket to update it.
推荐答案
更直接的解决方案是:http://www.devpicayune.com/entry/200609191448
import xmlrpclib
import socket
x = xmlrpclib.ServerProxy('http:1.2.3.4')
socket.setdefaulttimeout(10) #set the timeout to 10 seconds
x.func_name(args) #times out after 10 seconds
socket.setdefaulttimeout(None) #sets the default back
这篇关于为 xmlrpclib.ServerProxy 设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文