Repository navigation
Closed
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifeeasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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 = None
created_at = <Date 2020-07-25.14:12:10.580>
labels = ['easy', 'type-bug', '3.8', '3.9', '3.10', 'library']
title = "pickle and pickletools cli interface doesn't close input and output file."
updated_at = <Date 2022-04-05.13:05:47.595>
user = 'https://github.com/tirkarthi'bugs.python.org fields:
activity = <Date 2022-04-05.13:05:47.595>
actor = 'achhina'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-07-25.14:12:10.580>
creator = 'xtreak'
dependencies = []
files = []
hgrepos = []
issue_num = 41395
keywords = ['patch', 'easy']
message_count = 2.0
messages = ['374269', '416776']
nosy_count = 8.0
nosy_names = ['alexandre.vassalotti', 'python-dev', 'serhiy.storchaka', 'corona10', 'xtreak', 'Amir', 's.williams-wynn', 'achhina']
pr_nums = ['21676', '21702', '32257']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41395'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']Linked PRs
Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifeeasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
tirkarthi commentedon Jul 25, 2020
pickle and pickletools use argparse with FileType which is not automatically closed. Other cli interfaces like json [0], ast [1] use context manager to close filetype objects.
pickle :
cpython/Lib/pickle.py
Line 1799 in af08db7
mypickle
./python -Wall -m pickle mypickle
{'a': 1}
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='mypickle'>
pickletools :
cpython/Lib/pickletools.py
Lines 2850 to 2855 in af08db7
./python -Wall -m pickletools mypickle -o mypickle.py
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='mypickle'>
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='mypickle.py' mode='w' encoding='UTF-8'>
[0]
cpython/Lib/json/tool.py
Line 61 in af08db7
[1]
cpython/Lib/ast.py
Line 1510 in af08db7
achhina commentedon Apr 5, 2022
Hi,
First-time contributor here, I've made a patch in follow-up to the discussions that happened in Amir's patch in regards to this. I'd appreciate it if someone would be able to take a look and review it!
#32257
9 remaining items
Fix pickle and pickletools not closing files
furkanonder commentedon Nov 18, 2022
@serhiy-storchaka The issue seems to be resolved in this PR.
pythongh-85567: Fix resouce warnings in pickle and pickletools CLIs
serhiy-storchaka commentedon Jan 1, 2024
The
pickletoolsCLI is especially treacherous. It leaks the files if you specify the-targument. It leaks the output file if you only specify the output file argument. And of course it leaks the files in case of argument errors, for example specifying non-integer indent level or non-writeable output file.The only reliable way to handle this is to get rid of FileType and open and close files explicitly. PR #113618 does this.
gh-85567: Fix resouce warnings in pickle and pickletools CLIs (GH-113618
pythongh-85567: Fix resouce warnings in pickle and pickletools CLIs (p…
pythongh-85567: Fix resouce warnings in pickle and pickletools CLIs (p…
[3.11] gh-85567: Fix resouce warnings in pickle and pickletools CLIs (G…
[3.12] gh-85567: Fix resouce warnings in pickle and pickletools CLIs (G…
pythongh-85567: Fix resouce warnings in pickle and pickletools CLIs (p…
pythongh-85567: Fix resouce warnings in pickle and pickletools CLIs (p…
pythongh-85567: Fix resouce warnings in pickle and pickletools CLIs (p…