Question

I am using a number of different libraries, which each of which use different underlying ways to make socket connections, like urllib3, requests, and httplib. this is in python 2.7.5.

periodically, the program gets hung up in one of the libraries waiting for a network IO to complete.

I have tried socket.setdefaulttimeout(1.0) and socket._GLOBAL_DEFAULT_TIMEOUT = 1.0, and neither had any effect on my program.

what is the proper way to set a global socket timeout?

Was it helpful?

Solution

As the name of the function implies, setdefaulttimeout is just the default. If any of the other libs set the timeout on the socket, it will override this default.. So I see no choice but to set the timeout in each library explicitly

A complete answer can be found here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top