Neil Schemenauer added the comment:

Well, I just spent a couple of hours debugging a problem caused by this issue.  
You could argue that I should be calling close() on all of my file-like objects 
but I agree with Armin that the current "most of the time it works" behaviour 
is quite poor.

In my case, the issue is exactly what Antoine Pitrou suggests: if the FileIO 
object gets finalized before the BufferedIO object wrapping it then the 
buffered data gets lost. That depends on the order that the GC calls finalizers.

Armin's suggestion of keeping a list of open buffered files and flushing them 
before exiting seems like a simple and robust solution.  Having a warning for 
unclosed files is fine but in order to make porting Python 2 code as painless 
as possible, matching the safer behavior of Python 2 would be worth the extra 
bit of flush logic.

----------
nosy: +nascheme

_______________________________________
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