-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that the user-specified timeout is set before making a request #17
Conversation
This only takes effect on Python >= 2.6
Ah good find. It seems we respect the timeout after establishing the connection, but not if the the establishing step takes too long. For your specific patch, perhaps it would be better to check if But wouldn't this bug still exist if the connection hasn't been created yet, such as on the first attempt? |
The reason for using hasattr is that, starting with Python 2.6, httplib supports a timeout parameter in the HTTP(S)Connection constructors, thus solving the first connection attempt issue you describe. The code in the patch tries to determine if the |
Ah I see, thank you for the explanation! Sounds good. Let me think about this for a while to see if we can do this better somehow, if not then I'll merge your patch in next week. :) Please bug me if it hasn't happened! Thanks again. |
Thank you for considering the patch :) |
I dont' get it. There's no |
When the class is instantiated, if the This can be seen in Python's 2.6 httplib.py file: class HTTPConnection:
(...)
def __init__(self, host, port=None, strict=None,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
self.timeout = timeout
self.sock = None
(...) Maybe, specifying the conn = HTTPConnection(host=self.host, port=self.port)
conn.timeout = self.timeout
return conn In Python >= 2.6 the timeout value would be set; in Python < 2.6, the timeout attribute would have no effect. I don't favor any particular solution, as long as it works and you're happy with it :) |
I liked your latest version more, so I edited your commit and merged it with your original message/authorship. :) |
Cool. Thanks :) |
@piotr-dobrogost You're right, fixing. |
Hi,
urllib3 apparently does not honor the timeout value when establishing a new connection.
In the code, one can see that the timeout value is being set on the socket, albeit only after the connection attempt.
I believe this partly defeats the purpose of the timeout parameter.
Here's a small script that illustrates this:
Results
Without the change:
With the change:
Hope you find the patch useful.
Thank you for your work.