This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Arfrever, akira, martin.panter, piotr.dobrogost, pitrou, serhiy.storchaka, vstinner
Date 2016-03-25.13:22:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458912125.11.0.211388011359.issue19829@psf.upfronthosting.co.za>
In-reply-to
Content
> 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?
History
Date User Action Args
2016-03-25 13:22:05vstinnersetrecipients: + vstinner, pitrou, Arfrever, akira, martin.panter, piotr.dobrogost, serhiy.storchaka
2016-03-25 13:22:05vstinnersetmessageid: <1458912125.11.0.211388011359.issue19829@psf.upfronthosting.co.za>
2016-03-25 13:22:05vstinnerlinkissue19829 messages
2016-03-25 13:22:04vstinnercreate