Giter Club home page Giter Club logo

Comments (5)

piotr-dobrogost avatar piotr-dobrogost commented on May 18, 2024

@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.

shazow avatar shazow commented on May 18, 2024

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:

  1. 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?)
  2. Document release_conn param more thoroughly to describe the dependency on preload_content.
  3. Make preload_content=False default as planned in the next release.

I vote for 2 or 3.

from urllib3.

piotr-dobrogost avatar piotr-dobrogost commented on May 18, 2024

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.

shazow avatar shazow commented on May 18, 2024

Oops, that last commit should have been issue 23, not 22. Disregard it.

from urllib3.

shazow avatar shazow commented on May 18, 2024

Looks like we've moved on from this.

from urllib3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.