Skip to main content

A caching system for Numba with file locking support

Project description

numba-lock-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.lock for 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 minutes (configurable)
    • Lifetime: None (lock persists until released)
    • NFS-safe: relies on atomic file creation

Installation

pip install numba-lock-cache

How to use it

Just 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 * 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numba_cache_lock-0.1.0a2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numba_cache_lock-0.1.0a2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file numba_cache_lock-0.1.0a2.tar.gz.

File metadata

  • Download URL: numba_cache_lock-0.1.0a2.tar.gz
  • Upload date:
  • Size: 2.8 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

Hashes for numba_cache_lock-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 45f274356771ac3c8dbb3ee8a3ee27ba39769b25218ed1734c7e7c2b09bf52fb
MD5 2213265469b28b20cb99d7696ec9dfd8
BLAKE2b-256 e74266c2bf259487edc90e1da2bddc15b6cc216d12a61a6eca535807a6a908d2

See more details on using hashes here.

File details

Details for the file numba_cache_lock-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: numba_cache_lock-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 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

Hashes for numba_cache_lock-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 f626e77faac3c77f19c471b720f64a460d6941d6c83733bb5b1e754d4267ff2e
MD5 ca15f2fc0213ea0034a8bcfabfe86bda
BLAKE2b-256 b25fcfc3836e01bd7025f6df1ba70f41aee5fecdeb5dd102fe720ebaa4eb7b1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page