Skip to content

ClientSession.close deprecated when called directly via run_until_complete(2.2.3) #2065

Closed
@litwisha

Description

Long story short

When you close session directly via loop.run_until_complete(session.close()), it is deprecated.
The reason is that _CoroGuard inherits from _BaseCoroMixin that inherits from collections.abc.Coroutine.
https://github.com/aio-libs/aiohttp/blob/v2.2.3/aiohttp/helpers.py#L108
And when calling loop.run_until_complete(session.close()) then __await__ or __iter__ methods are unreachable, send method is called instead. That's why, self._awaited attribute is not changed to True.

Expected behaviour

Direct closing loop.run_until_complete(session.close()) is not deprecated

Actual behaviour

Direct closing loop.run_until_complete(session.close()) is deprecated

Steps to reproduce

import asyncio  
from aiohttp import ClientSession

loop = asyncio.get_event_loop()

session = ClientSession(loop=loop)
loop.run_until_complete(session.close())

Your environment

OS X 10.12.3
python 3.6.0
aiohttp==2.2.3

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions