STINNER Victor added the comment: > I think we should use one of Martin's option. If there are any issues with > garbage collecting, we should fix the garbage collector.
Ok, here is a new simpler proposition: remove all _dealloc_warn() method, and simply emit the ResourceWarning in IOBase finalizer. With this change, all objects which inherit from io.IOBase (or _pyio.IOBase) now emits a ResourceWarning if they are not closed explicitly. You have to override the __del__() method to prevent this warning. A lot of new objects start to log ResourceWarning: io.SocketIO, _pyio.TextIOWrapper, io.BytesIO, http.client.HTTPResponse, etc. For io.BytesIO, I fixed the code to inherit correctly IOBase finalizer. -- A lot of tests start to fail because they emit a lot of ResourceWarning warnings. I don't know yet if it's a feature or a bug :-) -- With the patch, Python starts to logs warnings like: sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'> sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'> You can use my patch of the issue #26642 to fix these warnings. ResourceWarning is emited even if FileIO.closefd is false. Note: It looks like the ResourceWarning is not always displayed. Yet another bug? ---------- Added file: http://bugs.python.org/file42291/iobase_finalizer.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19829> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com