Neil Schemenauer added the comment:

"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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17852>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to