##// END OF EJS Templates
Ensure files are closed after reading.
Bradley M. Froehle -
Show More
@@ -67,7 +67,8 b' class PickleShareDB(collections.MutableMapping):'
67 return self.cache[fil][0]
67 return self.cache[fil][0]
68 try:
68 try:
69 # The cached item has expired, need to read
69 # The cached item has expired, need to read
70 obj = pickle.loads(fil.open("rb").read())
70 with fil.open("rb") as f:
71 obj = pickle.loads(f.read())
71 except:
72 except:
72 raise KeyError(key)
73 raise KeyError(key)
73
74
@@ -82,7 +83,8 b' class PickleShareDB(collections.MutableMapping):'
82 parent.makedirs()
83 parent.makedirs()
83 # We specify protocol 2, so that we can mostly go between Python 2
84 # We specify protocol 2, so that we can mostly go between Python 2
84 # and Python 3. We can upgrade to protocol 3 when Python 2 is obsolete.
85 # and Python 3. We can upgrade to protocol 3 when Python 2 is obsolete.
85 pickled = pickle.dump(value,fil.open('wb'), protocol=2)
86 with fil.open('wb') as f:
87 pickled = pickle.dump(value, f, protocol=2)
86 try:
88 try:
87 self.cache[fil] = (value,fil.mtime)
89 self.cache[fil] = (value,fil.mtime)
88 except OSError,e:
90 except OSError,e:
General Comments 0
You need to be logged in to leave comments. Login now