Python xmlrpclib timeout
For my reference, and the reference of anyone who needs to find it, while playing around with the xmlrpclib module, I found myself needing to be able to adjust the timeout. As near as I can tell, if you don’t set a timeout value, it will run forever or at least a long time (I have never been willing to wait long enough to find out). The trick to giving xmlrpclib a timeout on calls to the server is importing and using the socket module. The following code example essentially covers what you can do:
import xmlrpclib import socket s = xmlrpclib.Server('http://myRemoteServerName/myEntryPoint') s.myProcedureName('hello input') #this call will not timeout... socket.setdefaulttimeout(10) #set the timeout to 10 seconds s.myProcedureName('hello input') #now the call will timout after 10 seconds socket.setdefaulttimeout(None) #set it back to no timeout value (if you want to)
The kicker here is just setting the defaulttimeout value in the socket module with the setdefaulttimeout method. If the RPC call times out, it will throw a timeout exception that you’ll need to be able to handle. But at least that’s better than the alternative of not ever timing out.
Technorati Tags: python, xmlrpc, xmlrpclib
3 comments3 Comments so far
Leave a reply
that was quite useful. the layout is bugged though, the line of code is way too long and doesn’t fit the screen;)
fixed the layout… sorry about that… I still need to fix it to use scrollable areas better…
Thanks,
This helped a lot!!
Cheers