Comments (5)
@shazow In the comment to release_conn
parameter to urlopen
method you wrote
This is useful if you're not preloading the response's content immediately.
It suggests we can't return connection to the pool before loading response's content but that's not the case, is it?
I guess the idea was to either release connection in HTTPConnectionPool.urlopen()
(if it's to be released automatically) or to pass it to HTTPResponse
(if it's not to be released automatically). Automatically releasing connection in HTTPResponse.read() goes against this idea by releasing connection which should not be released (that's why it was passed to HTTPResponse
). Removing code that releases connection in HTTPResponse.read()
makes all tests pass. What do you think?
from urllib3.
Alright I reinvestigated what I did when I wrote this and here's what's going on:
release_conn
only has an effect when preload_content=False
.
As you noticed, there's a convenience feature which automagically releases the connection once the full response has been read even when you specify release_conn=False
. To prevent this, you need to also specify preload_content=False
.
The reason for this is because we wanted to make preload_content=False
be default eventually (to promote on-demand loading which would make us perform better in benchmarks and generally more sane behaviour) and having release_conn
behave this way was a good way to set expectations for a future release without breaking backwards compatibility.
So here are the options:
- Remove this convenience feature and risk people forgetting to manually release the connection even after they've read the entire response. (Can we think of scenarios when we'd want to not release the connection even after we've read the entire response?)
- Document
release_conn
param more thoroughly to describe the dependency onpreload_content
. - Make
preload_content=False
default as planned in the next release.
I vote for 2 or 3.
from urllib3.
I'm not sure if I get this right.
The paramount question is this: is releasing a connection orthogonal to reading response's body? If it is I see no reason to make release_conn
depend on preload_content
.
Can we think of scenarios when we'd want to not release the connection even after we've read the entire response?
Yes, I think we should allow this. Someone, for instance, may want to do some request manually using such loose connection and then eventually return such connection to the pool.
The opposite situation is what I asked about here
It suggests we can't return connection to the pool before loading response's content but that's not the case, is it?
How about having 3 different states for release_conn
: immediately
, on_response_read
and never
?
from urllib3.
Oops, that last commit should have been issue 23, not 22. Disregard it.
from urllib3.
Looks like we've moved on from this.
from urllib3.
Related Issues (20)
- All Retry backoff_factor to optionally start applying from first retry HOT 4
- Retry backoff_factor offset from second retry incorrectly computed HOT 2
- HTTPConnection.request chunked=False doesn't work properly HOT 8
- Need to exception for "SSLEOFError" on python 3.10, 3.11, 3.12 HOT 3
- After upgrading to 2.2.1: 'HTTPResponse' object has no attribute 'json' HOT 1
- Comment typo settimout settimeout HOT 1
- Dependency management issue HOT 2
- Fix test_redirecting_to_bad_url failure in Requests HOT 12
- NodeJS + pyodide support HOT 1
- Retry.respect_retry_after_header=False is not honored when retry is incremented HOT 1
- Unable to build the doc `Command sphinx-build -b html -W . _build/html failed with exit code 2` HOT 1
- Sunsetting official support for Python 2
- Change log for version 1.26.19
- publish.yml uses two different versions of actions/download-artifact HOT 1
- requests > 2.31 - TypeError: unhashable type: 'list'
- pyproject.toml specifies an illegal value in the "dynamic" field HOT 4
- Cannot pass host parameter to PoolManager
- v2.0.5 is tagged strangely HOT 1
- Add support for HTTP/2 chunked request bodies HOT 1
- why this happens ?? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from urllib3.