A caching system for Numba with file locking support
Project description
numba-lock-cache
Intro
numba-lock-cache monkey-patch the Numba caching mechanism
smartjit @jit decorator adds extra customization of when code execution should fall back to the interpreter. It works as follow:
- For jitted functions with cache (overloads), use the jitted function if available, and interpreted code otherwise
- Add a dispatching logic, an optional function to pass to the jit decorator, which will decide wether to use jit or not.
Install
numba-smartjit is available on PyPI and can be installed with the command below:
pip install numba-smartjit
numba-locking-cache
A Python package that monkey-patches Numba's caching mechanism to safely coordinate concurrent cache access using file locks.
Why?
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)
Locking Mechanism
- 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
Installation
pip install numba-locking-cache
How to use it
Just import the patch Numba in your application:
import numba_locking_cache
numba_locking_cache.patch_numba_cache()
from numba import jit
@jit(cache=True)
def my_func(x):
return x * 2
By 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numba_cache_lock-0.1.0a1.tar.gz.
File metadata
- Download URL: numba_cache_lock-0.1.0a1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e523746d0df614cfaeefa29c544a751bfdb929abda9020c535e347ebafe48048
|
|
| MD5 |
e9d4cc7a8a735fe0142d5f15d9b8a392
|
|
| BLAKE2b-256 |
21fdbb65a8741dc25cf0955782b868c5cc0d40b24460634c85d7d24dd17d5187
|
File details
Details for the file numba_cache_lock-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: numba_cache_lock-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fb8a04fbfdb28c497fbbff56310864dbeb991bfa33cb85084ab97f304a81815
|
|
| MD5 |
90bd2fb389a2cdf968e6f2ff05eda8cb
|
|
| BLAKE2b-256 |
a46c6459502437d65b2d3d1473ae23ab40436a36fac3e0d3e0f64e57a3b899d0
|