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:45:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458913540.92.0.138284270703.issue19829@psf.upfronthosting.co.za>
In-reply-to
Content
Ok, I now understand the problem better. They are two kinds of io objects:

(1) object which directly or indirectly owns a limited resource like file descriptor => must emit a ResourceWarning
(2) object which don't own a limited resource => no ResourceWarning must be logged

Examples of (1): FileIO, BufferedReader(FileIO), TextIOWrapper(BufferedReader(FileIO))

Examples of (2): BytesIO, BuffereadReader(BytesIO), TextIOWrapper(BuffereadReader(BytesIO))


The tricky part is to decide if an object owns a limited resource or not. Currently, the io module uses the _dealloc_warn() trick. A close() method tries to call _dealloc_warn(), but it ignores any exception when calling _dealloc_warn(). BufferedReader calls raw._dealloc_warn(). TextIOWrapper calls buffer._dealloc_warn().


For case (1), BufferedReader(FileIO).close() calls FileIO._dealloc_warn() => ResourceWarning is logged

For case (2), BufferedReader(BytesIO).close() calls BytesIO._dealloc_warn() raises an AttributeError => no warning is logged


Well, we can call this a hack, but it works :-) pyio_res_warn-3.patch implements the same hack in _pyio.
History
Date User Action Args
2016-03-25 13:45:40vstinnersetrecipients: + vstinner, pitrou, Arfrever, akira, martin.panter, piotr.dobrogost, serhiy.storchaka
2016-03-25 13:45:40vstinnersetmessageid: <1458913540.92.0.138284270703.issue19829@psf.upfronthosting.co.za>
2016-03-25 13:45:40vstinnerlinkissue19829 messages
2016-03-25 13:45:40vstinnercreate