- if sb.st_mtime <= entry.mtime:
- return entry
-
- f = open(path)
- try:
- text = f.read()
- finally:
- f.close()
- code = compile(text, path, "exec")
- mod = types.ModuleType(mangle(path))
- mod.__file__ = path
- exec(code, mod.__dict__)
- entry = cachedmod(mod, sb.st_mtime)
- modcache[path] = entry
+ else:
+ entry = cachedmod()
+ modcache[path] = entry
+ with entry.lock:
+ if entry.mod is None or sb.st_mtime > entry.mtime:
+ with open(path, "rb") as f:
+ text = f.read()
+ code = compile(text, path, "exec")
+ mod = types.ModuleType(mangle(path))
+ mod.__file__ = path
+ exec(code, mod.__dict__)
+ entry.mod = mod
+ entry.mtime = sb.st_mtime