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-05-31.20:08:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1496261319.77.0.439465743849.issue17852@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-05-31 20:08:39naschemesetrecipients: + nascheme, tim.peters, arigo, vstinner, nikratio, neologix, martin.panter, serhiy.storchaka
2017-05-31 20:08:39naschemesetmessageid: <1496261319.77.0.439465743849.issue17852@psf.upfronthosting.co.za>
2017-05-31 20:08:39naschemelinkissue17852 messages
2017-05-31 20:08:39naschemecreate