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 Arusekk, martin.panter, nascheme, neologix, nikratio, nitishch, pitrou, serhiy.storchaka, tim.peters, vstinner, xgdomingo
Date 2018-01-25.00:13:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1516839200.6.0.467229070634.issue17852@psf.upfronthosting.co.za>
In-reply-to
Content
Using atexit is not the solution because the data can be lost even while the program is running, not just at interpreter shutdown.  The problem occurs if the buffered file object and the underlying file object are both part of a reference cycle.  Then, when the cycle is destroyed by the GC module, if the file __del__ is called before the buffer __del__, data is lost.

So far, the best solution I've come up with is as follows:  split the buffered file object into two objects, a wrapper object that will be returned from open() and an underlying object that holds the actual buffer.  Make the underlying file object keep references to all the buffers that are using the file.  When the file _del__ gets called, first flush all of the buffers and then close the file.  Splitting the buffered file object is required so that we don't create reference cycles.
History
Date User Action Args
2018-01-25 00:13:20naschemesetrecipients: + nascheme, tim.peters, pitrou, vstinner, nikratio, neologix, martin.panter, serhiy.storchaka, xgdomingo, nitishch, Arusekk
2018-01-25 00:13:20naschemesetmessageid: <1516839200.6.0.467229070634.issue17852@psf.upfronthosting.co.za>
2018-01-25 00:13:20naschemelinkissue17852 messages
2018-01-25 00:13:20naschemecreate