[New-bugs-announce] [issue38529] Python 3.8 improperly warns about closing properly closed streams

Ron Frederick report at bugs.python.org
Sat Oct 19 14:40:28 EDT 2019


New submission from Ron Frederick <ronf at timeheart.net>:

In testing AsyncSSH against Python 3.8, I noticed a large number of the following errors, even though I was properly closing streams before the objects holding them were garbage-collected.

    An open stream object is being garbage collected; call "stream.close()" explicitly.

After some investigation, the problem appears to be that closing a stream is not good enough to prevent the error. The check in asyncio doesn't properly handle the case where the stream is closing, but has not fully closed. Here's a simple test program that demonstrates this:

import asyncio

async def tcp_client():
    reader, writer = await asyncio.open_connection('127.0.0.1', 22)

    writer.close()

asyncio.run(tcp_client())

It's possible to avoid this message by awaiting on writer.wait_closed(), but wait_closed() doesn't exist until Python 3.7, making it very difficult to write portable code and still avoid this message.

----------
components: asyncio
messages: 354953
nosy: Ron Frederick, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Python 3.8 improperly warns about closing properly closed streams
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38529>
_______________________________________


More information about the New-bugs-announce mailing list