Skip to main content

Shared Memory Lock

A multiprocessing lock implemented using shared memory and atomics.

Installation

uv pip install -e .

Usage

from shared_memory_lock import SharedMemoryLock

# Create a lock (first process)
lock = SharedMemoryLock(name="my_lock", create=True, run_id="app1")

# Connect to the same lock (other processes)
lock = SharedMemoryLock(name="my_lock", create=False, run_id="app1")

# Use as context manager
with lock:
    # Critical section - only one process can be here
    print("Doing important work...")

# Or manual acquire/release
if lock.acquire(blocking=False):
    try:
        # Got the lock
        print("Acquired lock!")
    finally:
        lock.release()
else:
    print("Could not acquire lock")

# Clean up when done
lock.close()
lock.unlink()  # Only call from one process

Features

  • Cross-process synchronization: Works across multiple processes
  • Atomic operations: Uses real atomic compare-and-swap for mutual exclusion
  • Picklable: Can be passed to multiprocessing.Process
  • Context manager: Supports with statements
  • Non-blocking: Optional non-blocking acquire with timeout

Development

# Install dependencies
uv sync

# Run tests
uv run --python 3.13.7 pytest 

# Run tests with coverage
uv run --python 3.13.7 pytest --cov=shared_memory_lock

License

MIT

Metadata

Release files for shared_memory_lock 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shared_memory_lock 0.1.5
File Size Uploaded Provenance Actions
shared_memory_lock-0.1.5.tar.gz 10.7 kB Without provenance Details for shared_memory_lock-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shared_memory_lock 0.1.5
File Interpreter ABI Platform Actions
shared_memory_lock-0.1.5-py3-none-any.whl Python 3 none any Details for shared_memory_lock-0.1.5-py3-none-any.whl

Total release size: 17.4 kB

Release files / shared_memory_lock-0.1.5.tar.gz

Download URL shared_memory_lock-0.1.5.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
08b08a5561a2c490a9630c587eadda8cfb5170263cbf83d311487f6f8ab2619d
BLAKE2b-256 checksum
How to use checksums
d37a87f15e041328a43c70e039ffb97967c22a68ccdee45383abf4d388d67be6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release files / shared_memory_lock-0.1.5-py3-none-any.whl

Download URL shared_memory_lock-0.1.5-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fff1cadec203f0ac768c43d6bb34949aa0ced8b3c79d218445cea53d98c66345
BLAKE2b-256 checksum
How to use checksums
c7587d4ac30a152a1ee19a78788bf910da11f9acd6c4a6234fd4f6dd8cf3e3eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Security for shared_memory_lock 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page