提交 50924b23 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix crash in refresh when a cache dir contains a key.pkl but no dll.

上级 8917fa7d
...@@ -295,42 +295,42 @@ class ModuleCache(object): ...@@ -295,42 +295,42 @@ class ModuleCache(object):
except: except:
# the directory is still in use?? We just leave it for future removal. # the directory is still in use?? We just leave it for future removal.
pass pass
elif 'key.pkl' in files and (time_now - last_access_time(module_name_from_dir(root)))<self.age_thresh_use: elif 'key.pkl' in files:
key_pkl = os.path.join(root, 'key.pkl')
debug('refresh adding', key_pkl)
try: try:
key = cPickle.load(open(key_pkl, 'rb')) entry = module_name_from_dir(root)
except: except ValueError: # there is a key but no dll!
info("ModuleCache.refresh() Failed to unpickle cache key", key_pkl) warning("ModuleCache.refresh() Found key without dll in cache, deleting it.", key_pkl)
if 0:
info("Erasing broken cache directory", key_pkl)
shutil.rmtree(root)
else:
## This exception is often triggered by keys that contain
# references to classes that have not yet been imported. They are
# not necessarily broken
pass
continue
if not key[0]: #if the version is False
warning("ModuleCache.refresh() Found unversioned key in cache, deleting it.", key_pkl)
info("Erasing broken cache directory", key_pkl) info("Erasing broken cache directory", key_pkl)
shutil.rmtree(root) shutil.rmtree(root)
continue continue
if (time_now - last_access_time(module_name_from_dir(root)))<self.age_thresh_use:
if key not in self.entry_from_key: key_pkl = os.path.join(root, 'key.pkl')
debug('refresh adding', key_pkl)
try: try:
entry = module_name_from_dir(root) key = cPickle.load(open(key_pkl, 'rb'))
except ValueError: # there is a key but no dll! except:
warning("ModuleCache.refresh() Found key without dll in cache, deleting it.", key_pkl) info("ModuleCache.refresh() Failed to unpickle cache key", key_pkl)
if 0:
info("Erasing broken cache directory", key_pkl)
shutil.rmtree(root)
else:
## This exception is often triggered by keys that contain
# references to classes that have not yet been imported. They are
# not necessarily broken
pass
continue
if not key[0]: #if the version is False
warning("ModuleCache.refresh() Found unversioned key in cache, deleting it.", key_pkl)
info("Erasing broken cache directory", key_pkl) info("Erasing broken cache directory", key_pkl)
shutil.rmtree(root) shutil.rmtree(root)
continue continue
self.entry_from_key[key] = entry if key not in self.entry_from_key:
# assert that we haven't already got this entry somehow self.entry_from_key[key] = entry
assert entry not in self.module_from_name # assert that we haven't already got this entry somehow
self.loaded_key_pkl.add(key_pkl) assert entry not in self.module_from_name
self.loaded_key_pkl.add(key_pkl)
# remove entries that are not in the filesystem # remove entries that are not in the filesystem
items_copy = list(self.entry_from_key.iteritems()) items_copy = list(self.entry_from_key.iteritems())
...@@ -352,7 +352,7 @@ class ModuleCache(object): ...@@ -352,7 +352,7 @@ class ModuleCache(object):
info("deleting ModuleCache entry", entry) info("deleting ModuleCache entry", entry)
del self.entry_from_key[key] del self.entry_from_key[key]
if key[0]: if key[0]:
# this is a versioned entry, so should have been on disk # this is a versioned entry, so should have been on disk
# Something weird happened to cause this, so we are responding by # Something weird happened to cause this, so we are responding by
# printing a warning, removing evidence that we ever saw this mystery # printing a warning, removing evidence that we ever saw this mystery
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论