Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
bpo-41395: Close file objects in pickle and pickletools#21676
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
the-knights-who-say-ni commentedJul 29, 2020
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed thePSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find abugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please followthe steps outlined in the CPython devguide to rectify this issue. You cancheck yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Using both pickle and pickletools from the command line raised a resource warning indicating that the file objects were not closed after use.
@@ -1814,4 +1814,5 @@ def _test(): | |||
import pprint | |||
for f in args.pickle_file: | |||
obj = load(f) | |||
f.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This will not be called ifload
causes exception for cases like invalid payload. Similar case with the approach inpickletools
too. Sometimes even if one file causes exception the other files in the loop will not be iterated and closed.
$ echo invalid > mypickle.pickle$ ./python -Wall -m pickle mypickle.pickleTraceback (most recent call last): File "/root/cpython/Lib/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/root/cpython/Lib/runpy.py", line 87, in _run_code exec(code, run_globals) File "/root/cpython/Lib/pickle.py", line 1816, in <module> obj = load(f)_pickle.UnpicklingError: could not find MARKsys:1: ResourceWarning: unclosed file <_io.BufferedReader name='mypickle.pickle'>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
hmm.. good catch. I'll use another approach.
Uh oh!
There was an error while loading.Please reload this page.
File objects were not closed after reading their contents resulting in the following resource warning:
This change ensures that the file is closed after reading the contents.
closes:https://bugs.python.org/issue41395
https://bugs.python.org/issue41395