Issue 18853: Got ResourceWarning unclosed file when running Lib/shlex.py demo (original ) (raw )Created on 2013-08-27 14:04 by vajrasky , last changed 2022-04-11 14:57 by admin . This issue is now closed .
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/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.
msg196583 - (view)
Author: Terry J. Reedy (terry.reedy) *
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) *
Date: 2014-06-25 10:25
It seems commit ready.
msg229622 - (view)
Author: Roundup Robot (python-dev)
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. https://hg.python.org/cpython/rev/4c2b77d0680b New changeset 8ed630f28753 by R David Murray in branch 'default': Merge: #18853 : Fix resource warning in shlex's __main__ section. https://hg.python.org/cpython/rev/8ed630f28753
msg229623 - (view)
Author: R. David Murray (r.david.murray) *
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.
History
Date
User
Action
Args
2022-04-11 14:57:50
admin
set
github: 63053
2014-10-18 00:34:52
r.david.murray
set
status: open -> closednosy: + r.david.murray messages: + resolution: fixedstage: commit review -> resolved
2014-10-18 00:30:28
python-dev
set
nosy: + python-dev messages: +
2014-06-27 03:46:48
ezio.melotti
set
versions: - Python 3.3
2014-06-25 10:25:04
Claudiu.Popa
set
versions: + Python 3.5nosy: + Claudiu.Popa messages: + stage: patch review -> commit review
2013-09-04 19:07:22
ezio.melotti
set
nosy: + ezio.melotti
2013-08-30 21:58:57
madison.may
set
nosy: + madison.may messages: +
2013-08-30 21:55:35
terry.reedy
set
versions: + Python 2.7, Python 3.3nosy: + terry.reedy messages: + stage: patch review
2013-08-27 14:04:27
vajrasky
create