You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python 3.8 improperly warns about closing properly closed streams #82710
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:
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.
I think the following change might address this problem:
*** 233,239 ****
def \_on_reader_gc(self, wr):
transport = self.\_transport
! if transport is not None:
# connection_made was called
context = {
'message': ('An open stream object is being garbage '
--- 233,239 ----
def_on_reader_gc(self, wr):
transport=self._transport
! iftransportisnotNoneandnottransport.is_closing():
# connection_made was calledcontext= {
'message': ('An open stream object is being garbage '
RonFrederick commented on Oct 27, 2019
RonFrederickmannequin
MannequinAuthor
More actions
Sorry, I should have said that the change below was in the file asyncio/streams.py.
Activity
RonFrederick commentedon Oct 19, 2019
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.
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:
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.
RonFrederick commentedon Oct 27, 2019
I think the following change might address this problem:
*** 233,239 ****
! if transport is not None:
# connection_made was called
context = {
'message': ('An open stream object is being garbage '
--- 233,239 ----
def _on_reader_gc(self, wr): transport = self._transport ! if transport is not None and not transport.is_closing(): # connection_made was called context = { 'message': ('An open stream object is being garbage 'RonFrederick commentedon Oct 27, 2019
Sorry, I should have said that the change below was in the file asyncio/streams.py.
1st1 commentedon Oct 27, 2019
Yes, I've experienced this bug. We need to fix this in 3.8.1.
asvetlov commentedon Dec 7, 2019
New changeset 7ddcd0c by Andrew Svetlov in branch 'master':
bpo-38529: Fix asyncio stream warning (GH-17474)
7ddcd0c
miss-islington commentedon Dec 7, 2019
New changeset 7fde4f4 by Miss Islington (bot) in branch '3.8':
bpo-38529: Fix asyncio stream warning (GH-17474)
7fde4f4