classification
Title: Closed files keep their buffer alive
Type: resource usage Stage: resolved
Components: IO, Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jcea Nosy List: benjamin.peterson, hynek, jcea, meador.inge, pitrou, python-dev, serhiy.storchaka, stutzbach
Priority: low Keywords: patch

Created on 2012-07-29 17:56 by pitrou, last changed 2012-10-04 10:39 by jcea. This issue is now closed.

Files
File name Uploaded Description Edit
a16403affccd jcea, 2012-08-01 03:17 review
53aa92a70127.diff jcea, 2012-10-04 10:39 review
Repositories containing patches
http://hg.jcea.es/cpython-2011/#buffering-issue15488
Messages (8)
msg166801 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-07-29 17:56
>>> f = open("LICENSE", "rb")
>>> sys.getsizeof(f)
4296
>>> f.close()
>>> sys.getsizeof(f)
4296

Instead of waiting for the file object's deallocation, perhaps we should free the buffer when it is closed?
msg166804 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-07-29 19:09
Sounds reasonable to me.
msg167076 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-08-01 02:45
I take care of this.
msg167080 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-08-01 03:18
Please, review patch
msg167081 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-08-01 04:11
The test should go in the 'SizeofTest' class and maybe a better test would be a variant of the test already in that class:

    @support.cpython_only
    def test_buffer_freeing(self) :
        bufsize = 4096
        rawio = self.MockRawIO()
        bufio = self.tp(rawio, buffer_size=bufsize)
        size = sys.getsizeof(bufio) - bufsize
        bufio.close()
        self.assertEqual(sys.getsizeof(bufio), size)

Otherwise, LGTM.
msg167097 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-08-01 07:51
Agree with Meador.
msg167117 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-08-01 12:09
This has to wait for 3.4, since it's an enhancement, not a bug.
msg171931 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-04 10:38
New changeset 4141c36954cd by Jesus Cea in branch 'default':
Closes #15488: Closed files keep their buffer alive
http://hg.python.org/cpython/rev/4141c36954cd
History
Date User Action Args
2012-10-04 10:39:22jceasetfiles: + 53aa92a70127.diff
keywords: + patch
2012-10-04 10:38:44python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg171931

resolution: fixed
stage: patch review -> resolved
2012-08-01 12:09:35pitrousetmessages: + msg167117
versions: + Python 3.4, - Python 3.3
2012-08-01 07:51:37serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg167097
2012-08-01 04:11:52meador.ingesetmessages: + msg167081
2012-08-01 03:18:11jceasetmessages: + msg167080
stage: patch review
2012-08-01 03:17:10jceasetfiles: + a16403affccd
2012-08-01 03:07:27jceasetversions: - Python 3.4
2012-08-01 02:45:36jceasetassignee: jcea
messages: + msg167076
hgrepos: + hgrepo143
2012-08-01 00:51:20jceasetnosy: + jcea
2012-07-29 19:09:44benjamin.petersonsetmessages: + msg166804
2012-07-29 18:04:58meador.ingesetnosy: + meador.inge
2012-07-29 17:56:44pitrousetnosy: + benjamin.peterson, stutzbach, hynek
2012-07-29 17:56:31pitroucreate