This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Got ResourceWarning unclosed file when running Lib/ demo
Type: resource usage Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, ezio.melotti, madison.may, python-dev, r.david.murray, terry.reedy, vajrasky
Priority: normal Keywords: patch

Created on 2013-08-27 14:04 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
fix_resource_warning_shlex_test.patch vajrasky, 2013-08-27 14:04 review
Messages (6)
msg196291 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-08-27 14:04
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/ /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.
msg196583 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-30 21:55
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.
msg196585 - (view) Author: Madison May (madison.may) * Date: 2013-08-30 21:58
The patch LGTM as well.

ResourceWarning was silenced after applying patch when tested on my machine.
msg221540 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-06-25 10:25
It seems commit ready.
msg229622 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-18 00:30
New changeset 4c2b77d0680b by R David Murray in branch '3.4':
#18853: Fix resource warning in shlex's __main__ section.

New changeset 8ed630f28753 by R David Murray in branch 'default':
Merge: #18853: Fix resource warning in shlex's __main__ section.
msg229623 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-18 00:34
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.
Date User Action Args
2022-04-11 14:57:50adminsetgithub: 63053
2014-10-18 00:34:52r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg229623

resolution: fixed
stage: commit review -> resolved
2014-10-18 00:30:28python-devsetnosy: + python-dev
messages: + msg229622
2014-06-27 03:46:48ezio.melottisetversions: - Python 3.3
2014-06-25 10:25:04Claudiu.Popasetversions: + Python 3.5
nosy: + Claudiu.Popa

messages: + msg221540

stage: patch review -> commit review
2013-09-04 19:07:22ezio.melottisetnosy: + ezio.melotti
2013-08-30 21:58:57madison.maysetnosy: + madison.may
messages: + msg196585
2013-08-30 21:55:35terry.reedysetversions: + Python 2.7, Python 3.3
nosy: + terry.reedy

messages: + msg196583

stage: patch review
2013-08-27 14:04:27vajraskycreate