Title: I/O object wrappers shouldn't close their underlying file when deleted.
Type: enhancement Stage: resolved
Components: IO Versions: Python 3.2
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 2010-08-05 07:32 by alexandre.vassalotti. 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()
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.
Date User Action Args
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