A Python package that monkey-patches Numba's caching mechanism to safely coordinate concurrent cache access using file locks.
Numba’s function-level caching (@jit(cache=True)) is not concurrency-safe by default. This can lead to:
- Crashes when multiple processes load/write to the same cache
- Especially problematic on shared filesystems (e.g., NFS)
- Uses
flufl.lockfor file-based locking. - Lock file is created next to the cache index file:
/path/to/cache/func.nbi.lock - Lock behavior:
- Timeout to acquire: 60 seconds (configurable)
- Lifetime:
None(lock persists until released) - NFS-safe: relies on atomic file creation
pip install numba-lock-cacheJust import the patch Numba in your application:
import numba_cache_lock
numba_cache_lock.patch_numba_cache()
from numba import jit
@jit(cache=True)
def my_func(x):
return x * 2By default, patch_numba_cache will hold a lock for 1 hour in the worst case.
One can change this value by assigning the lifetime= keyword argument to a
timedelta object.