8000 Close file objects after reading contents · python/cpython@8c3991b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c3991b

Browse files
committed
Close file objects after reading contents
Using both pickle and pickletools from the command line raised a resource warning indicating that the file objects were not closed after use.
1 parent a74eea2 commit 8c3991b

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

Lib/pickle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,4 +1814,5 @@ def _test():
18141814
import pprint
18151815
for f in args.pickle_file:
18161816
obj = load(f)
1817+
f.close()
18171818
pprint.pprint(obj)

Lib/pickletools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,9 +2882,11 @@ def _test():
28822882
elif len(args.pickle_file) == 1:
28832883
dis(args.pickle_file[0], args.output, None,
28842884
args.indentlevel, annotate)
2885+
args.pickle_file[0].close()
28852886
else:
28862887
memo = {} if args.memo else None
28872888
for f in args.pickle_file:
28882889
preamble = args.preamble.format(name=f.name)
28892890
args.output.write(preamble + '\n')
28902891
dis(f, args.output, memo, args.indentlevel, annotate)
2892+
f.close()

0 commit comments

Comments
 (0)
0