Set timeout for xmlrpclib.ServerProxy

前端 未结 9 1670
轮回少年
轮回少年 2020-12-29 22:33

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.

9条回答
  •  甜味超标
    2020-12-29 23:03

    An more straightforward solution is at: 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
    

提交回复
热议问题