Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set timeout for xmlrpclib.ServerProxy

Tags:

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.

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.

like image 650
ashchristopher Avatar asked Dec 16 '08 19:12

ashchristopher


1 Answers

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 
like image 133
azarias Avatar answered Nov 06 '22 04:11

azarias