[issue17852] Built-in module _io can lose data from buffered files at exit

Neil Schemenauer report at bugs.python.org
Thu Dec 14 14:27:01 EST 2017


Neil Schemenauer <nas-python at arctrix.com> added the comment:

Attached is a script that triggers the non-flushing behaviour for me.  I don't think it is reliable since it depends on the order that FileIO AND BufferedWriter are finalized when the gc finds them in a reference cycle.

BTW, it is arguable that the root cause of this bug is that we no longer to topological ordering when calling finalizers.  Originally, the cycle GC would refuse to call __del__ methods because once they are part of a cycle, there is no defined topological ordering.  So, we linked that garage to gc.garbage rather than calling __del__ and have potentially undefined results.  Now the GC has been changed to call __del__ anyhow.   I haven't studied how this has been changed but this non-flushing bug is a result.  Having the buffer added to gc.garbage would also result in the data not being flushed but arguably it would be more understandable what's going on.  I'm not arguing that we should go back to that, just that current behaviour can be subtle and confusing.

----------
Added file: https://bugs.python.org/file47332/buffer_not_flushed.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue17852>
_______________________________________


More information about the Python-bugs-list mailing list