Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed files keep their buffer alive #59693

Closed
pitrou opened this issue Jul 29, 2012 · 8 comments
Closed

Closed files keep their buffer alive #59693

pitrou opened this issue Jul 29, 2012 · 8 comments
Assignees
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir topic-IO

Comments

@pitrou
Copy link
Member

pitrou commented Jul 29, 2012

BPO 15488
Nosy @jcea, @pitrou, @benjaminp, @meadori, @hynek, @serhiy-storchaka
Files
  • a16403affccd
  • 53aa92a70127.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/jcea'
    closed_at = <Date 2012-10-04.10:38:44.199>
    created_at = <Date 2012-07-29.17:56:31.987>
    labels = ['library', 'expert-IO', 'performance']
    title = 'Closed files keep their buffer alive'
    updated_at = <Date 2012-10-04.10:39:22.753>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2012-10-04.10:39:22.753>
    actor = 'jcea'
    assignee = 'jcea'
    closed = True
    closed_date = <Date 2012-10-04.10:38:44.199>
    closer = 'python-dev'
    components = ['Library (Lib)', 'IO']
    creation = <Date 2012-07-29.17:56:31.987>
    creator = 'pitrou'
    dependencies = []
    files = ['26638', '27413']
    hgrepos = ['143']
    issue_num = 15488
    keywords = ['patch']
    message_count = 8.0
    messages = ['166801', '166804', '167076', '167080', '167081', '167097', '167117', '171931']
    nosy_count = 8.0
    nosy_names = ['jcea', 'pitrou', 'benjamin.peterson', 'stutzbach', 'meador.inge', 'python-dev', 'hynek', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue15488'
    versions = ['Python 3.4']

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 29, 2012

    >>> 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?

    @pitrou pitrou added stdlib Python modules in the Lib dir topic-IO performance Performance or resource usage labels Jul 29, 2012
    @benjaminp
    Copy link
    Contributor

    Sounds reasonable to me.

    @jcea
    Copy link
    Member

    jcea commented Aug 1, 2012

    I take care of this.

    @jcea jcea self-assigned this Aug 1, 2012
    @jcea
    Copy link
    Member

    jcea commented Aug 1, 2012

    Please, review patch

    @meadori
    Copy link
    Member

    meadori commented Aug 1, 2012

    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.

    @serhiy-storchaka
    Copy link
    Member

    Agree with Meador.

    @pitrou
    Copy link
    Member Author

    pitrou commented Aug 1, 2012

    This has to wait for 3.4, since it's an enhancement, not a bug.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 4, 2012

    New changeset 4141c36954cd by Jesus Cea in branch 'default':
    Closes bpo-15488: Closed files keep their buffer alive
    http://hg.python.org/cpython/rev/4141c36954cd

    @python-dev python-dev mannequin closed this as completed Oct 4, 2012
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    performance Performance or resource usage stdlib Python modules in the Lib dir topic-IO
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants