Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
s3bw wants to merge2 commits intopython:masterfroms3bw:bpo-41395-close-file

Conversation

s3bw
Copy link
Contributor

@s3bws3bw commentedJul 29, 2020
edited by bedevere-bot
Loading

File objects were not closed after reading their contents resulting in the following resource warning:

$ ./python.exe-Wall-mpicklemypickle{'a':1}sys:1:ResourceWarning:unclosedfile<_io.BufferedReadername='mypickle'>

This change ensures that the file is closed after reading the contents.

$ ./python.exe-Wall-mpicklemypickle{'a':1}

closes:https://bugs.python.org/issue41395

https://bugs.python.org/issue41395

@the-knights-who-say-ni

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 username

We couldn't find abugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@Foxyblue

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.
@s3bws3bwforce-pushed thebpo-41395-close-file branch fromcb64f86 tof09f836CompareJuly 29, 2020 18:19
@s3bws3bw changed the titlebpo-41395: Close file object after reading contentsbpo-41395: Close file objects in pickle and pickletoolsJul 29, 2020
@@ -1814,4 +1814,5 @@ def _test():
import pprint
for f in args.pickle_file:
obj = load(f)
f.close()
Copy link
Member

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'>

Copy link
ContributorAuthor

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tirkarthitirkarthitirkarthi left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@s3bw@the-knights-who-say-ni@tirkarthi@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp