IndexDataCacheFile.save: 解锁的读-修改-写操作允许两个缓存键共享一个 .nbc 文件,因此一个签名可以加载另一个签名的编译代码
作者: shaunc创建于 2026年9月27日更新于 2026年9月28日
标签more info needed
numba/core/caching.py (current main, and 0.62.1):
def save(self, key, data):
overloads = self._load_index() # (1) read the whole index
try:
data_name = overloads[key]
except KeyError:
existing = set(overloads.values())
for i in itertools.count(1): # (2) pick the LOWEST unused number
data_name = self._data_name(i)
if data_name not in existing:
break
overloads[key] = data_name
self._save_index(overloads) # (3) write the whole index back
self._save_data(data_name, data) # (4) write the .nbc_open_for_write makes each individual file write atomic (uuid temp +
os.replace), which is why this reads as safe on inspection. But nothing
serialises steps (1)–(4) across processes. Interleaving two processes P1 (key A)
and P2 (key B), both starting from the same index state:
内容来源: numba/numba