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.

classification
Title: I/O object wrappers shouldn't close their underlying file when deleted.
Type: enhancement Stage: resolved
Components: IO Versions: Python 3.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, benjamin.peterson, pitrou
Priority: normal Keywords:

Created on 2009-06-29 00:49 by alexandre.vassalotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg89803 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-06-29 00:49
Here's an example of the behaviour:

import io

def test(buf):
   textio = io.TextIOWrapper(buf)

buf = io.BytesIO()
test(buf)
print(buf.closed)  # This prints True currently


The problem here is TextIOWrapper closes its buffer when deleted.
BufferedRWPair behalves similarly. The solution is simply to override
the __del__ method of TextIOWrapper inherited from IOBase.
msg89827 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-06-29 11:46
You can call the detach() method if you don't want to the underlying
stream to be closed.
We could also add a close_parent attribute defaulting to True.
msg112954 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2010-08-05 07:32
OK I am convinced, the current behavior is fine. Let's close this one.
History
Date User Action Args
2022-04-11 14:56:50adminsetgithub: 50610
2010-08-05 07:32:50alexandre.vassalottisetstatus: open -> closed
resolution: wont fix
messages: + msg112954

stage: needs patch -> resolved
2009-06-29 11:46:06pitrousetnosy: + pitrou, benjamin.peterson
messages: + msg89827

components: + IO
type: behavior -> enhancement
2009-06-29 00:49:51alexandre.vassalotticreate