You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pickle and pickletools cli interface doesn't close input and output file. #85567
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.
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!
The pickletools CLI is especially treacherous. It leaks the files if you specify the -t argument. 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.
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…