STINNER Victor added the comment:

Is anyone interested to work on the "maintain a list of open file objects" idea?

I consider that Python 3 does its best to flush data at exit, but it's not a 
good practice to rely on the destructors to flush data. I mean, there is no 
warranty that files will be written in the correct order and that files will 
stay consistent. It's much safer to explicitly call the clode() method.

By the way, Python 3 now emits ResourceWarning warnings when files are 
destroyed without being explicitly closed. I enhanced the code handling 
warnings during Python shutdown to show these warnings in more use cases, but 
it is still not perfect. I opened the issue #21788 as a reminder that the code 
can still be enhanced.

For the "maintain a list of objects" idea, I expect race conditions with 
threads, signals and processes (fork). We already have known issues with locks 
+ fork. I expect even more issues if we maintain a list of open files.

I propose to close the issue as "wontfix". Python 3 does its best, but please 
call explicitly the close() method!

Maybe the undefined behaviour should be documented (with a warning?) in the 
buffered writer of the io module, and maybe also in the open() function?

----------

_______________________________________
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

Reply via email to