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
User guide for how to provide timeouts #5789
Comments
All of your issues describe providing one timeout for a session rather than how to provide timeouts for requests. It sounds like you thus want to add an example of a recipe to the documentation that shows people how to create their own session object that accepts a timeout and passes that on to every request the session makes? Is that accurate? If not, can you please explain (perhaps with an example) what you're thinking needs to be added exactly? |
In more general terms it’s mostly about pre-configuring request parameters (eg. authentication, headers, …) so that not every part of the code initiating a request needs to care about all these details. For most of these parameters sessions can be used for exactly that, which is perhaps the reason why people tend to think about putting the timeout there as well. I actually don’t mind what the concept of encapsulating these parameters is called. What matters is that it accomplishes the encapsulation and is easy to use.
I’d suggest to:
So the open questions for me are:
|
Absolutely not. Ignoring the mounds of hate mail I've received for a decision I didn't make, but frankly agree with, this would then make it seem like "the library authors encourage this but won't support it" which will cause a flood of new issues and pull requests for something that we won't be adding. If there are other improvements around session attributes you can point out that you think are missing, I'm happy to review a PR adding those |
I’m really sorry to hear you are getting hate mail for any decision made in an open source project. I definitely like to avoid that. I’m also not suggesting to revise that decision. I’m trying to find ways to implement it. Do you also disagree with 1.? (making this decision visible in the docs)
I think the “this“ is important in this sentence: Do you think there is absolutely no sensible way to achieve an encapsulation of the timeout that fits the decision & the design of the library? … even for specific use-cases? — For me it seems that at least this comment includes a way to do this that doesn’t bind the timeout to the session at all. I imagine most developers who end up bringing this to the issue queue go through a process roughly like this:
I think adding something to the docs would catch them before they are too invested in the idea that the Session is the right place to add this. Pointing them to a recipy that solves their problem would avoid them coming to the issue queue altogether — even if it’s a “We don’t recommend this, but some users have found this useful.” |
Hi there, Remember this lib , is just a user-friendly or elegant HTTP Requests implementation , based on urllib3 , so...it depends on urllib and it depends on socket lib....if you are loking for a more deep implementation, I would suggest you to use adapters and look for tcp session params on python..you can set session and connection timeouts, while urllib release a easy way to set then. Cheers |
It seems reasonable that this should be emphasized more in the docs since it won't be supported directly. Quickstart > Timeouts is the second to last section and contains this gotcha:
The default behavior blocks forever under relatively common and transient network conditions, and almost every example in the documentation outside of the Timeout section itself shows this usage. If a default timeout does not belong to the Or perhaps the other Quickstart examples should always be passing the |
You say It also seems completely self-contradictory for the documentation to suggest that "nearly every request should have a timeout" while the library doesn't provide a convenient way to specify a default timeout rather than repeating it on every request, and neither does the documentation provide a recipe for subclassing If adding it to HTTPAdapter itself isn't a workable solution for whatever reason, maybe it could go in |
Exactly. And that’s why it’s worth looking for a user-friendly way to support a very common use-case — I daresay code that needs a timeout is more common than code that doesn’t. So perhaps we are talking about nothing less than the most common use case for this library and how to make it less error prone. |
Potentially instead of a changing the timeout property / attribute itself, would it make sense to offer the ability to warn when no timeout is set, similar to how more recent python versions can warn about using |
Hi, let me revive the discussion. I stumbled upon the "default timeout" issue recently. I think that a very simple solution, like global default timeout that is applied to all the requests when no more specific timeout is provided, would address many operational pains. I would imagine that such a timeout could be set with some I'd happily provide a PR for such a feature, I'd like to know though which direction would be the best one. |
This is one of the reasons why I would use httpx which has an easy to use solution for timeouts for new projects. For my current projects I’d hope to migrate at some point. I’m closing this issue now as I don’t have hopes that the maintainers will agree to improvements of either the code or the documentation of the library before I migrate. |
As many others before me I have the need to set a default timeout for all requests (blocking forever just isn’t a very good default in most cases I guess).
I appreciate that this has been covered exhaustingly in this issue queue, that there might not be a recommendation for all use-cases, and there are different ways to do this.
That’s exactly why I’m proposing to add documentation at the appropriate places for this in order to improve the experience for downstream developers and to avoid further mayhem in the issue queue.
So what are recommendable ways to have a default timeout and which disadvantages / advantages do they have?
The text was updated successfully, but these errors were encountered: