Skip to content
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

Add warning about unclosed AsyncClient #871

Closed
kamilglod opened this issue Mar 23, 2020 · 8 comments · Fixed by #1197
Closed

Add warning about unclosed AsyncClient #871

kamilglod opened this issue Mar 23, 2020 · 8 comments · Fixed by #1197
Labels
concurrency Issues related to concurrency and usage of async libraries enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@kamilglod
Copy link

It would be nice to have an info about some unclosed AsyncClient() instance. Here is an example how it is implemented in aiohttp: https://github.com/aio-libs/aiohttp/blob/693ed0cce0c67646f8df18c93e448d10782c2811/aiohttp/client.py#L268-L286

@florimondmanca florimondmanca added the concurrency Issues related to concurrency and usage of async libraries label Mar 25, 2020
@florimondmanca
Copy link
Member

Hi @kamilglod

Can you share what the UX for this in aiohttp looks like? (eg maybe a snippet of an interactive interpreter session…)

I'm just wondering if this would actually provide value, or just add noise when shutting down an interpreter (which should force-close any dangling resources anyway, no?).

@kamilglod
Copy link
Author

@florimondmanca closing all connections sounds fine but question is whether it is technically doable as close() is an async function and we cannot await it inside __dell__(). Additionally I think that such an information is very helpful in tracking buggy code with unclosed resources
Here is an example output from aiohttp:
Screenshot from 2020-03-25 12-40-08

@florimondmanca
Copy link
Member

florimondmanca commented Mar 25, 2020

Thanks, the REPL snippet is useful.

An implementation similar to aiohttp is technically possible — ie log a warning but don’t attempt to close the client (notably because, as you said, it’s an async operation).

One bit to keep in mind is that this would need to be async library agnostic (asyncio/trio) - so the check needs to be deferred to the async backends at some point - so this doesn’t seem like a trivial addition. But if you’d like to give it a shot feel free to. :)

@florimondmanca florimondmanca added enhancement New feature or request good first issue Good for newcomers labels Mar 28, 2020
@Pradhvan
Copy link

@florimondmanca If anyone is not working on it. I would like to give it a try. 😄

@Pradhvan
Copy link

I was setting up the project locally and in the step of installing dependencies. Should it explicitly mention that scripts/install will automatically create a virtual environment?

You can now install the project and its dependencies using:
$ cd httpx
$ scripts/install

Or is it just me that went ahead creating a virtual env and running the command scripts/install hoping it would install dependencies in the environment I created.

@tomchristie tomchristie added this to the v1.0 milestone Jul 30, 2020
@cdeler
Copy link
Member

cdeler commented Aug 17, 2020

@Pradhvan do you mind if I take this?

@cdeler
Copy link
Member

cdeler commented Aug 18, 2020

@florimondmanca should we add the similar check for httpx.Client?

@Pradhvan
Copy link

@cdeler yes 😄

cdeler added a commit to cdeler/httpx that referenced this issue Aug 19, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 19, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 19, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 19, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 21, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 21, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 21, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 26, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 31, 2020
All over the AsyncClient invocation is made using context manager or with try-finally block
cdeler added a commit to cdeler/httpx that referenced this issue Aug 31, 2020
All over the AsyncClient invocation is made using context manager or with try-finally block
cdeler added a commit that referenced this issue Aug 31, 2020
All over the AsyncClient invocation is made using context manager or with try-finally block
cdeler added a commit to cdeler/httpx that referenced this issue Aug 31, 2020
cdeler added a commit to cdeler/httpx that referenced this issue Aug 31, 2020
tomchristie added a commit that referenced this issue Sep 2, 2020
* Made Client and AsyncClient checking for being closed in __del__ (#871)

* Changed the AsyncClient closing warning type from ResourceWarning (which is too quiet) to UserWarning  (#871)

* Fixed tests and client's __exit__ and __aexit__ after the difficult merge (#871)

* Update test_proxies.py

* Update test_proxies.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency Issues related to concurrency and usage of async libraries enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants