提交 4d4fd6d8 authored 作者: Zach Ploskey's avatar Zach Ploskey

close files after we open them

上级 aca7c197
...@@ -476,8 +476,8 @@ class KeyData(object): ...@@ -476,8 +476,8 @@ class KeyData(object):
""" """
# Note that writing in binary mode is important under Windows. # Note that writing in binary mode is important under Windows.
try: try:
cPickle.dump(self, open(self.key_pkl, 'wb'), with open(self.key_pkl, 'wb') as f:
protocol=cPickle.HIGHEST_PROTOCOL) cPickle.dump(self, f, protocol=cPickle.HIGHEST_PROTOCOL)
except cPickle.PicklingError: except cPickle.PicklingError:
_logger.warning("Cache leak due to unpickle-able key data %s", _logger.warning("Cache leak due to unpickle-able key data %s",
self.keys) self.keys)
...@@ -681,7 +681,8 @@ class ModuleCache(object): ...@@ -681,7 +681,8 @@ class ModuleCache(object):
"unpickle cache file %s", key_pkl) "unpickle cache file %s", key_pkl)
try: try:
key_data = cPickle.load(open(key_pkl, 'rb')) with open(key_pkl, 'rb') as f:
key_data = cPickle.load(f)
except EOFError: except EOFError:
# Happened once... not sure why (would be worth # Happened once... not sure why (would be worth
# investigating if it ever happens again). # investigating if it ever happens again).
...@@ -1126,7 +1127,9 @@ class ModuleCache(object): ...@@ -1126,7 +1127,9 @@ class ModuleCache(object):
# Verify that when we reload the KeyData from the pickled file, the # Verify that when we reload the KeyData from the pickled file, the
# same key can be found in it, and is not equal to more than one # same key can be found in it, and is not equal to more than one
# other key. # other key.
key_data = cPickle.load(open(key_pkl, 'rb')) with open(key_pkl, 'rb') as f:
key_data = cPickle.load(f)
found = sum(key == other_key for other_key in key_data.keys) found = sum(key == other_key for other_key in key_data.keys)
msg = '' msg = ''
if found == 0: if found == 0:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论