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 martin.panter
Recipients Arfrever, akira, martin.panter, pitrou, serhiy.storchaka, vstinner
Date 2015-02-14.02:00:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1423879234.78.0.00240585748872.issue19829@psf.upfronthosting.co.za>
In-reply-to
Content
One option would be for any wrapper-type class (e.g. BufferedReader, SocketIO) to override __del__(). Instead of calling close(), it should call detach() or equivalent, and delete the returned reference to the underlying wrapped object without explicitly closing it, to allow a warning to be generated. Maybe a WrappedIO mixin class could help with this.

I am posting del-detach.patch which roughly implements the above option. It only seems to break the test_override_destructor() tests for the TextIOWrapperTest and CommonBufferedTests classes, which expect close() to be called.

Another more radical option might be to make IOBase.__del__() only call flush(), not close(), except for the actual implementations that really should emit a warning, like FileIO. I will have a go at doing this option in another patch.

Both these options would change the behaviour in some cases that rely on the garbage collector to close objects. They would defer the automatic closing until all references of the underlying object are garbage collected, instead of just when the wrapped object is garbage collected. A third option would be to add explicit __del__() methods emitting a warning in each class, along with any exception supression needed due to Python interpreter finalization quirks.
History
Date User Action Args
2015-02-14 02:00:34martin.pantersetrecipients: + martin.panter, pitrou, vstinner, Arfrever, akira, serhiy.storchaka
2015-02-14 02:00:34martin.pantersetmessageid: <1423879234.78.0.00240585748872.issue19829@psf.upfronthosting.co.za>
2015-02-14 02:00:34martin.panterlinkissue19829 messages
2015-02-14 02:00:33martin.pantercreate