[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2021-09-21 Thread STINNER Victor
STINNER Victor added the comment: While it would be great to also emit ResourceWarning, in the last 8 years, nobody managed to implement the feature. Also, this issue has no activity. I prefer to close the issue. -- resolution: -> out of date stage: needs patch -> resolved status: o

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-26 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > Serhiy: why did you add 2.7 to this bug? For 2.7, I don’t think anything > should be done. There is no ResourceWarning in 2.7. Just for the case. Not calling close() in __del__() is one option, and it looks attractive. But there are possible hidden catche

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread Martin Panter
Martin Panter added the comment: In the long term, I prefer not calling close() in __del__(), like del-flush.patch, although I admit it is an API change and should probably be limited to 3.6+. If people want to improve things in 3.5, privately implementing _dealloc_warn() like Victor’s pyio_re

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: 1. What if only object which directly owns a limited resource will emit a ResourceWarning? This can break some tests, but may be these tests are too strong? Current GC may be better than when io classes were implemented. 2. An object which indirectly owns a

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread STINNER Victor
STINNER Victor added the comment: 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 mu

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread STINNER Victor
STINNER Victor added the comment: > For io.BytesIO, I fixed the code to inherit correctly IOBase finalizer. Oh, I forgot to include it in my patch. But it's maybe better to have it in a different patch: see attached bytesio_stringio.patch which changes also io.StringIO to inherit the IOBase fi

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-25 Thread STINNER Victor
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 fina

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
STINNER Victor added the comment: > I don't like _dealloc_warn() at all. It looks as a dirty hack and doesn't > work with custom file-like objects. I tried to support emitting a ResourceWarning when the close() method is overriden in a subclass, but then I saw that io doesn't support this use

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I don't like _dealloc_warn() at all. It looks as a dirty hack and doesn't work with custom file-like objects. I think we should use one of Martin's option. If there are any issues with garbage collecting, we should fix the garbage collector. -- vers

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
STINNER Victor added the comment: Try attached res_warn.py script to test manually all ResourceWarning warnings. Ouput of python3.6 -Wd res_warn.py: -- text <_pyio.TextIOWrapper name='/etc/issue' mode='r' encoding='UTF-8'> res_warn.py:9: ResourceWarning: unclosed file <_p

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
STINNER Victor added the comment: del-detach.patch: I don't understand the change in _pyio.py. I think that the change on socket.py is no more need since the change 46329eec5515 (issue #26590). del-flush.patch: * change on IOBase.__del__() change the behaviour compared to the io module, I don

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
STINNER Victor added the comment: Oh, the io module is more complex than what I expected :-) test_io fails with pyio_res_warn-2.patch. test_io now pass with pyio_res_warn-3.patch. I fixed FileIO.close() to always call super().close(), and set self._fd to -1 even if logging the ResourceWarning

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
STINNER Victor added the comment: (oops, there was a typo in my first patch) -- Added file: http://bugs.python.org/file42272/pyio_res_warn-2.patch ___ Python tracker ___

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
Changes by STINNER Victor : Removed file: http://bugs.python.org/file42271/pyio_res_warn.patch ___ Python tracker ___ ___ Python-bugs-list mai

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2016-03-24 Thread STINNER Victor
STINNER Victor added the comment: Attached patch modifies _pyio to mimick better the reference io module: * Add IOBase._finalizing * IOBase.__del__() sets _finalizing to True * Add FileIO._dealloc_warn() * Remove FileIO.__del__() * FileIO.close(), _BufferedIOMixin.close() and TextIOWrapper.close

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2015-02-13 Thread Martin Panter
Changes by Martin Panter : Added file: http://bugs.python.org/file38136/del-flush.patch ___ Python tracker ___ ___ Python-bugs-list mailing li

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2015-02-13 Thread Martin Panter
Changes by Martin Panter : Removed file: http://bugs.python.org/file38135/del-flush.patch ___ Python tracker ___ ___ Python-bugs-list mailing

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2015-02-13 Thread Martin Panter
Martin Panter added the comment: Posting del-flush.patch, which only calls flush() instead of close() from __del__(), except for the FileIO class. Quick analysis of resulting test failures: These tests fail because they are obviously written to test that __del__ calls close(): * IOTest.test_I

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2015-02-13 Thread Martin Panter
Martin Panter added the comment: 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 closin

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2015-02-13 Thread Martin Panter
Martin Panter added the comment: It looks like the C _io close() implementations delegate to the wrapped object’s undocumented _dealloc_warn() method to emit the warning if “self->finalizing” is set. For wrapped objects like BytesIO that do not have it, I guess the error due to the missing met

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2014-07-27 Thread Akira Li
Akira Li added the comment: Related issue21859 "Add Python implementation of FileIO" -- nosy: +akira ___ Python tracker ___ ___ Python

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2014-04-18 Thread Martin Panter
Changes by Martin Panter : -- nosy: +vadmium ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2013-11-29 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis : -- nosy: +Arfrever ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2013-11-29 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I think it will be good. -- components: +IO stage: -> needs patch type: -> resource usage versions: +Python 2.7 ___ Python tracker ___ _

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2013-11-29 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:

[issue19829] _pyio.BufferedReader and _pyio.TextIOWrapper destructor don't emit ResourceWarning if the file is not closed

2013-11-29 Thread STINNER Victor
New submission from STINNER Victor: $ ./python Python 3.4.0b1 (default:acabd3f035fe, Nov 28 2013, 15:04:09) [GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import _pyio >>> f=_pyio.open("/etc/issue"); f=None >>> f=_pyio.o