Aiohttp: Unclosed client session warning

Created on 15 Sep 2016  路  6Comments  路  Source: aio-libs/aiohttp

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)

client outdated question

Most helpful comment

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.

All 6 comments

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

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?!

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.

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings