提交 bd862ae9 authored 作者: Frederic's avatar Frederic

make less useless file system access

上级 19976b0c
...@@ -308,12 +308,13 @@ def last_access_time(path): ...@@ -308,12 +308,13 @@ def last_access_time(path):
return os.stat(path)[stat.ST_ATIME] return os.stat(path)[stat.ST_ATIME]
def module_name_from_dir(dirname, err=True): def module_name_from_dir(dirname, err=True, files=None):
""" """
Scan the contents of a cache directory and return full path of the Scan the contents of a cache directory and return full path of the
dynamic lib in it. dynamic lib in it.
""" """
files = os.listdir(dirname) if files is None:
files = os.listdir(dirname)
names = [file for file in files names = [file for file in files
if file.endswith('.so') or file.endswith('.pyd')] if file.endswith('.so') or file.endswith('.pyd')]
if len(names) == 0 and not err: if len(names) == 0 and not err:
...@@ -654,7 +655,7 @@ class ModuleCache(object): ...@@ -654,7 +655,7 @@ class ModuleCache(object):
msg="delete.me found in dir") msg="delete.me found in dir")
elif 'key.pkl' in files: elif 'key.pkl' in files:
try: try:
entry = module_name_from_dir(root) entry = module_name_from_dir(root, files=files)
except ValueError: # there is a key but no dll! except ValueError: # there is a key but no dll!
if not root.startswith("/tmp"): if not root.startswith("/tmp"):
# Under /tmp, file are removed periodically by the # Under /tmp, file are removed periodically by the
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论