This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nascheme
Recipients arigo, martin.panter, nascheme, neologix, nikratio, serhiy.storchaka, tim.peters, vstinner
Date 2017-06-01.16:25:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1496334336.08.0.514228533814.issue17852@psf.upfronthosting.co.za>
In-reply-to
Content
"Did you get any ResourceWarning?"

I already knew that explicitly closing the file would fix the issue.  However, think of the millions of lines of Python 2 that hopefully will be converted to Python 3.  There will be many ResourceWarning errors.  It is not reasonable to think that everyone is just going to fix them when they see them.  Applications that used to be reliable will now randomly lose data.

What I spent hours debugging is trying to figure out why when the open file is collected on interpreter exit, buffered data not flushed.  I knew the object was not part of an uncollectable garbage cycle.  I initially suspected there could be some bug in the _io module or maybe even a kernel bug.

It turns out that in Python 2 the buffer and the open file is a single object and so when the finalizer gets called, the data is always correctly written out.  In Python 3, the buffer and the underlying file object are separate and they can get finalized in different order depending on essentially random factors.

Fixing this particular issue is not difficult as Armin's code demonstrates.  I don't think blaming the application programmer is the solution.  Obviously we keep the warnings and still tell programmers to close their files or use context managers.
History
Date User Action Args
2017-06-01 16:25:36naschemesetrecipients: + nascheme, tim.peters, arigo, vstinner, nikratio, neologix, martin.panter, serhiy.storchaka
2017-06-01 16:25:36naschemesetmessageid: <1496334336.08.0.514228533814.issue17852@psf.upfronthosting.co.za>
2017-06-01 16:25:36naschemelinkissue17852 messages
2017-06-01 16:25:35naschemecreate