提交 4c320661 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Some fixes to new cache mechanism

上级 77223d49
...@@ -408,18 +408,32 @@ class ModuleCache(object): ...@@ -408,18 +408,32 @@ class ModuleCache(object):
continue continue
if (time_now - last_access_time(entry)) < self.age_thresh_use: if (time_now - last_access_time(entry)) < self.age_thresh_use:
debug('refresh adding', key_pkl) debug('refresh adding', key_pkl)
def unpickle_failure():
info("ModuleCache.refresh() Failed to unpickle "
"cache file", key_pkl)
try: try:
key_data = cPickle.load(open(key_pkl, 'rb')) key_data = cPickle.load(open(key_pkl, 'rb'))
except EOFError:
# Happened once... not sure why (would be worth
# investigating).
unpickle_failure()
warning("Erasing broken cache directory [EOF]", root)
shutil.rmtree(root)
continue
except: except:
info("ModuleCache.refresh() Failed to unpickle " # For now, raise exceptions, in order to be able to
"cache file", key_pkl) # figure out which exceptions should be caught.
# TODO Make it more user-friendly by not raising
# the exception.
raise
unpickle_failure()
if False: if False:
info("Erasing broken cache directory", key_pkl) info("Erasing broken cache directory", root)
shutil.rmtree(root) shutil.rmtree(root)
else: else:
# This exception is often triggered by keys that contain # This exception is often triggered by keys that contain
# references to classes that have not yet been imported. They are # references to classes that have not yet been imported. They are
# not necessarily broken # not necessarily broken.
pass pass
continue continue
...@@ -665,16 +679,25 @@ class ModuleCache(object): ...@@ -665,16 +679,25 @@ class ModuleCache(object):
too_old_to_use = [(None, entry) for entry in too_old_to_use] too_old_to_use = [(None, entry) for entry in too_old_to_use]
time_now = time.time() time_now = time.time()
# the .items() is important here: # the .iteritems() is important here:
# we need to get a copy of the whole list of keys and entries # we need to get a copy of the whole list of keys and entries
items_copy = list(self.entry_from_key.iteritems()) items_copy = list(self.entry_from_key.iteritems())
for key, entry in items_copy + too_old_to_use: all_items = items_copy + too_old_to_use
# Since multiple keys may share the same entry, we turn this list
# of pairs into a dictionary that maps an entry to the list of keys
# that use it.
entry_to_keys = dict((entry, [])
for key, entry in all_items)
for key, entry in all_items:
entry_to_keys[entry].append(key)
for entry, keys in entry_to_keys.iteritems():
age = time_now - last_access_time(entry) age = time_now - last_access_time(entry)
if age > age_thresh_del: if age > age_thresh_del:
# TODO: we are assuming that modules that haven't been accessed in over # TODO: we are assuming that modules that haven't been accessed in over
# age_thresh_del are not currently in use by other processes, but that could be # age_thresh_del are not currently in use by other processes, but that could be
# false for long-running jobs... # false for long-running jobs...
assert entry not in self.module_from_name assert entry not in self.module_from_name
for key in keys:
if key is not None: if key is not None:
del self.entry_from_key[key] del self.entry_from_key[key]
parent = os.path.dirname(entry) parent = os.path.dirname(entry)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论