Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure files are closed after reading.

  • Loading branch information...
commit cb578674d7000f3f27aa13b553d0fef1aaa3f10b 1 parent b1a8e9d
@bfroehle bfroehle authored
Showing with 4 additions and 2 deletions.
  1. +4 −2 IPython/utils/pickleshare.py
View
6 IPython/utils/pickleshare.py
@@ -67,7 +67,8 @@ def __getitem__(self,key):
return self.cache[fil][0]
try:
# The cached item has expired, need to read
- obj = pickle.loads(fil.open("rb").read())
+ with fil.open("rb") as f:
+ obj = pickle.loads(f.read())
except:
raise KeyError(key)
@@ -82,7 +83,8 @@ def __setitem__(self,key,value):
parent.makedirs()
# We specify protocol 2, so that we can mostly go between Python 2
# and Python 3. We can upgrade to protocol 3 when Python 2 is obsolete.
- pickled = pickle.dump(value,fil.open('wb'), protocol=2)
+ with fil.open('wb') as f:
+ pickled = pickle.dump(value, f, protocol=2)
try:
self.cache[fil] = (value,fil.mtime)
except OSError,e:
Please sign in to comment.
Something went wrong with that request. Please try again.