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

STINNER Victor report at bugs.python.org
Thu Dec 4 12:05:04 CET 2014


STINNER Victor added the comment:

> The problem is that the order of tp_finalize calls is arbitrary when there is a reference cycle

If we want to guaranty that all files are properly flushed at exit, the best option is to maintain a list of open files.

I'm not interested to implement that, it sounds too complex. For example, open("text.txt", "w") creates 3 objects: FileIO, BufferedWriter, TextIOWrapper. You have to register these 3 objects and flush them in the right order. Python is dynamic, you are free to modify objects, for example using the detach() method or by modifying the buffer attribute of the TextIOWrapper.

How do you decide which object should be flushed? In which order? We have to take care of signals, threads and forks, stay portable, etc.

----------

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


More information about the Python-bugs-list mailing list