Neil Schemenauer <nas-pyt...@arctrix.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://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