Serhiy Storchaka added the comment: How it looks to me. Should be global collection of weak references (WeakSet?). Every instance of TextIOWrapper, BufferedWriter and BufferedRandom add itself to this collection on create and remove on close. A function registered with atexit calls flush() for all methods in the collection.
This solution doesn't require changes to finalization machinery, only to the io module. I'm not particularly interested to implement that because I'm not convinced that Python should provide such guaranties. But the implementation shouldn't be too complex. More general solution could be to introduce special method (__predel__) which should be called before breaking reference loops (or just before __del__ if there is no loop). In case of output streams it will call flush() (but not close()!). ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17852> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com