Thanks to visit codestin.com
Credit goes to github.com

Skip to content

asyncio stream.py: Is async context manager code correct? #12995

@peterhinch

Description

@peterhinch

Link to code

    async def __aexit__(self, exc_type, exc, tb):
        await self.close()

    def close(self):
        pass

If used in an asynchronous context manager it seems that the socket is not closed.

[EDIT]
The CPython docs make no reference to async context managers. They do say of StreamReader:

As an asynchronous iterable, the object supports the async for statement.

This doesn't appear to be supported but would be useful.

Further, on StreamWriter.close() the docs say:

The method closes the stream and the underlying socket.

In a microcontroller context failing to close sockets (read and write) is a regular cause of OOM errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    extmodRelates to extmod/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions