I am using Python’s xmlrpclib to make requests to an xml-rpc service.
Is there a way to set a client timeout, so my requests don’t hang forever when the server is not available?
I know I can globally set a socket timeout with socket.setdefaulttimeout(), but that is not preferable.
The clean approach is to define and use a custom transport, e.g.:
! this will work only for python2.7 !
There’s an example of defining and using a custom transport in the docs, though it’s using it for a different purpose (access via a proxy, rather than setting timeouts), this code is basically inspired by that example.