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

Got ResourceWarning unclosed file when running Lib/shlex.py demo #63053

Closed
vajrasky mannequin opened this issue Aug 27, 2013 · 6 comments
Closed

Got ResourceWarning unclosed file when running Lib/shlex.py demo #63053

vajrasky mannequin opened this issue Aug 27, 2013 · 6 comments
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Aug 27, 2013

BPO 18853
Nosy @terryjreedy, @ezio-melotti, @bitdancer, @PCManticore, @vajrasky
Files
  • fix_resource_warning_shlex_test.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 2014-10-18.00:34:52.309>
    created_at = <Date 2013-08-27.14:04:27.420>
    labels = ['library', 'performance']
    title = 'Got ResourceWarning unclosed file when running Lib/shlex.py demo'
    updated_at = <Date 2014-10-18.00:34:52.307>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2014-10-18.00:34:52.307>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-10-18.00:34:52.309>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2013-08-27.14:04:27.420>
    creator = 'vajrasky'
    dependencies = []
    files = ['31485']
    hgrepos = []
    issue_num = 18853
    keywords = ['patch']
    message_count = 6.0
    messages = ['196291', '196583', '196585', '221540', '229622', '229623']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'ezio.melotti', 'r.david.murray', 'Claudiu.Popa', 'python-dev', 'madison.may', 'vajrasky']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue18853'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Aug 27, 2013

    The python is compiled with --with-pydebug flag.

    [sky@localhost cpython]$ cat /tmp/quote.txt
    manly "man" likes 'cute "cat"'
    [sky@localhost cpython]$ ./python Lib/shlex.py /tmp/quote.txt
    Token: 'manly'
    Token: '"man"'
    Token: 'likes'
    Token: '\'cute "cat"\''
    sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/quote.txt' mode='r' encoding='UTF-8'>

    Attached the patch to close the file when running the demo.

    @vajrasky vajrasky mannequin added stdlib Python modules in the Lib dir performance Performance or resource usage labels Aug 27, 2013
    @terryjreedy
    Copy link
    Member

    I think the warning should be silenced on all versions where it occurs. There is no real problem here, but there can be with multiple opens without close on non-refcounted interpreters. Patch looks good but I have not tried it.

    @MadisonMay
    Copy link
    Mannequin

    MadisonMay mannequin commented Aug 30, 2013

    The patch LGTM as well.

    ResourceWarning was silenced after applying patch when tested on my machine.

    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jun 25, 2014

    It seems commit ready.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 18, 2014

    New changeset 4c2b77d0680b by R David Murray in branch '3.4':
    bpo-18853: Fix resource warning in shlex's __main__ section.
    https://hg.python.org/cpython/rev/4c2b77d0680b

    New changeset 8ed630f28753 by R David Murray in branch 'default':
    Merge: bpo-18853: Fix resource warning in shlex's __main__ section.
    https://hg.python.org/cpython/rev/8ed630f28753

    @bitdancer
    Copy link
    Member

    Thanks for the patch, Vajrasky, but I chose a different fix, since the proposed one could leave the file open if the shlex constructor raised an error. Not particularly important, but as long as we are cleaning up the code we might as well make it as clean as we can.

    Since 2.7 doesn't generate ResourceWarnings I chose not to apply it there.

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants