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

ResourceWarning: unclosed transport #1115

Closed
jwilk opened this issue Aug 24, 2016 · 2 comments
Closed

ResourceWarning: unclosed transport #1115

jwilk opened this issue Aug 24, 2016 · 2 comments
Labels
invalid This doesn't seem right outdated

Comments

@jwilk
Copy link
Contributor

jwilk commented Aug 24, 2016

Long story short

I'd like my software be warning-free.

Expected behaviour

Correct use of asyncio doesn't cause any warnings.

Actual behaviour

ResourceWarning: unclosed transport is emitted.

Steps to reproduce

Put this in test.py:

import asyncio
import aiohttp

async def main(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            await response.read()

url = 'https://example.org/'
loop = asyncio.get_event_loop()
loop.run_until_complete(main(url))
loop.close()

Then run:

$ python3 -Wd test.py 
/usr/lib/python3.5/asyncio/selector_events.py:582: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=7>
  warnings.warn("unclosed transport %r" % self, ResourceWarning)

Your environment

aiohttp from git master (d8848dd), Python 3.5.2, Linux.

@asvetlov asvetlov added the invalid This doesn't seem right label Aug 25, 2016
@asvetlov
Copy link
Member

The issue cannot be solved, sorry.
The reason is: after calling transport.close() asyncio needs for extra loop iteration for actual closing.
It's by design.
So if you add await asyncio.sleep(0) just before loop closing -- warning disappears.

If you want -- please feel free to add a note section to aiohttp documentation for stressing the behavior.
Perhaps it should be somewhere at very end of http://aiohttp.readthedocs.io/en/stable/client.html

@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
invalid This doesn't seem right outdated
Projects
None yet
Development

No branches or pull requests

2 participants