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

Unclosed client session warning #1175

Closed
tahajahangir opened this issue Sep 15, 2016 · 6 comments
Closed

Unclosed client session warning #1175

tahajahangir opened this issue Sep 15, 2016 · 6 comments
Labels

Comments

@tahajahangir
Copy link
Contributor

Long story short

We see rare logs with error level ERROR saying Unclosed client session during normal operation.

Expected behaviour

No log!

Actual behaviour

Sample log:

2016-09-14 18:42:28,511 ERROR asyncio Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fd2b06469b0>

As an aiohttp user, can we do anythin to prevent unclosed sessions? If no, it's better to have a specific warning class (subclass of ResourceWarning), not just using the original base class.

Steps to reproduce

Cannot reproduce manually!

Your environment

Debian 8
Python 3.5.2
aiohttp (0.22.5)

@asvetlov
Copy link
Member

Either use async with aiohttp.ClientSession() as session: ... or call await session.close() explicitly.

@asvetlov asvetlov added question StackOverflow client labels Sep 15, 2016
@tahajahangir
Copy link
Contributor Author

tahajahangir commented Sep 15, 2016

We don't use ClientSession directly:

async with aiohttp.post(check_url, data=data) as resp:
    if resp.status == 200:
        return await resp.json()

Is it wrong?!

@asvetlov
Copy link
Member

It's deprecated and removed from the documentation's usage part.
Perhaps we had reasons for it, isn't it?
And the main reason is impossibility to provide steady graceful shutdown with this API.

@Kentzo
Copy link

Kentzo commented Sep 16, 2016

@asvetlov Unfortunately warnings.warn is not a widely adopted (or known?) technique. And even fewer users know in advance that particular package utilizes it.

Maybe a banner should be added to the tutorial stating that? Or even a suggestion to turn warnings into exceptions?

@asvetlov
Copy link
Member

Teaching users to working with warnings is out of scope of this project.
I don't want to mess tutorials with banners like notes or warnings.
Even Django (super newbie friendly tool) just uses DeprecationWarning.

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants