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

FD leaks in ZipFile.read(), ZipFile.extract() and also using explicit arc_member.close() #57342

Closed
ValeryKhamenya mannequin opened this issue Oct 8, 2011 · 5 comments
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir topic-IO

Comments

@ValeryKhamenya
Copy link
Mannequin

ValeryKhamenya mannequin commented Oct 8, 2011

BPO 13133
Nosy @amauryfa, @meadori
Files
  • zipfiletest.py
  • zipfile.patch
  • 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 = None
    closed_at = <Date 2012-10-15.13:23:34.440>
    created_at = <Date 2011-10-08.18:48:54.807>
    labels = ['library', 'expert-IO', 'performance']
    title = 'FD leaks in ZipFile.read(), ZipFile.extract() and also using explicit arc_member.close()'
    updated_at = <Date 2012-10-15.13:23:34.439>
    user = 'https://bugs.python.org/ValeryKhamenya'

    bugs.python.org fields:

    activity = <Date 2012-10-15.13:23:34.439>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-10-15.13:23:34.440>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'IO']
    creation = <Date 2011-10-08.18:48:54.807>
    creator = 'Valery.Khamenya'
    dependencies = []
    files = ['23347', '23354']
    hgrepos = []
    issue_num = 13133
    keywords = ['patch']
    message_count = 5.0
    messages = ['145182', '145185', '145188', '145191', '145250']
    nosy_count = 3.0
    nosy_names = ['amaury.forgeotdarc', 'meador.inge', 'Valery.Khamenya']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue13133'
    versions = ['Python 2.7']

    @ValeryKhamenya
    Copy link
    Mannequin Author

    ValeryKhamenya mannequin commented Oct 8, 2011

    The attached file reproduces 3 types of FD leaks and leads to the error like:

    IOError: [Errno 24] Too many open files: '/tmp/1019'

    For example if executed with pypy.

    @ValeryKhamenya ValeryKhamenya mannequin added stdlib Python modules in the Lib dir topic-IO performance Performance or resource usage labels Oct 8, 2011
    @meadori
    Copy link
    Member

    meadori commented Oct 8, 2011

    I can't reproduce this problem in either 2.7.2 or 3.3.0a0.

    For example if executed with pypy.

    Do you mean that this problem is only reproducible when the attached
    script is run with pypy?

    @ValeryKhamenya
    Copy link
    Mannequin Author

    ValeryKhamenya mannequin commented Oct 8, 2011

    "I can't reproduce this problem in either 2.7.2 or 3.3.0a0."

    You probably mean CPython implementation of Python. No, I didn't mean this implementation.

    "Do you mean that this problem is only reproducible when the attached
    script is run with pypy?"

    I can't say "only". I just could say yes, it is reproducible with pypy. Perhaps, there are others Python implementations that will suffer from the bug in current implementation of ZipFile

    @amauryfa
    Copy link
    Member

    amauryfa commented Oct 8, 2011

    Yes, in 2.7 many parts of the stdlib relies on reference counting to close files. But 3.2 introduced a ResourceWarning which is emitted (in debug mode) each time a __del__ closes a valuable resource like a file or a socket. This was done exactly for this reason - help other implementations with a different garbage collector.

    Now Lib/zipfile.py is probably much more gc-friendly: see how it uses a new member "close_fileobj", and the "with" statement in ZipFile.read().

    PyPy will benefit of this when it migrates to 3.2; meanwhile, you could apply the same changes in pypy's own copy of zipfile.py.

    @ValeryKhamenya
    Copy link
    Mannequin Author

    ValeryKhamenya mannequin commented Oct 9, 2011

    Amaury, I followed your advice. All relevant changes of 3.2 are backported via the patch attached.

    P.S. now I can install Twisted using pypy too. "pypy setup.py install" works fine for me.

    @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

    3 participants