# Shared Memory Lock
A multiprocessing lock implemented using shared memory and atomics.
## Installation
```bash
uv pip install -e .
```
## Usage
```python
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
```bash
# 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
Raw data
{
"_id": null,
"home_page": null,
"name": "shared_memory_lock",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.13.7",
"maintainer_email": null,
"keywords": "multiprocessing, lock, synchronization, atomic, shared-memory",
"author": null,
"author_email": "Raymond Chastain <RaymondLC92@protonmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a0/c4/b5f4702f9a131576bfb4edc83330253984bce2fcb136598a70513d07b428/shared_memory_lock-0.1.0.tar.gz",
"platform": null,
"description": "# Shared Memory Lock\n\nA multiprocessing lock implemented using shared memory and atomics.\n\n## Installation\n\n```bash\nuv pip install -e .\n```\n\n## Usage\n\n```python\nfrom shared_memory_lock import SharedMemoryLock\n\n# Create a lock (first process)\nlock = SharedMemoryLock(name=\"my_lock\", create=True, run_id=\"app1\")\n\n# Connect to the same lock (other processes)\nlock = SharedMemoryLock(name=\"my_lock\", create=False, run_id=\"app1\")\n\n# Use as context manager\nwith lock:\n # Critical section - only one process can be here\n print(\"Doing important work...\")\n\n# Or manual acquire/release\nif lock.acquire(blocking=False):\n try:\n # Got the lock\n print(\"Acquired lock!\")\n finally:\n lock.release()\nelse:\n print(\"Could not acquire lock\")\n\n# Clean up when done\nlock.close()\nlock.unlink() # Only call from one process\n```\n\n## Features\n\n- **Cross-process synchronization**: Works across multiple processes\n- **Atomic operations**: Uses real atomic compare-and-swap for mutual exclusion\n- **Picklable**: Can be passed to multiprocessing.Process\n- **Context manager**: Supports `with` statements\n- **Non-blocking**: Optional non-blocking acquire with timeout\n\n## Development\n\n```bash\n# Install dependencies\nuv sync\n\n# Run tests\nuv run --python 3.13.7 pytest \n\n# Run tests with coverage\nuv run --python 3.13.7 pytest --cov=shared_memory_lock\n```\n\n## License\n\nMIT\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A multiprocessing lock implemented using shared memory and atomics.",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [
"multiprocessing",
" lock",
" synchronization",
" atomic",
" shared-memory"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "cb9cba5d4efe502dd46a6ee25377777e35e69487384d8164e6f2119844934958",
"md5": "fab3c8fceda61a72e297b8950e246b86",
"sha256": "2c4eb8aa2af0be68144702f78f5a74635402161290ce4ceb4c05616d467e1133"
},
"downloads": -1,
"filename": "shared_memory_lock-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fab3c8fceda61a72e297b8950e246b86",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.13.7",
"size": 4284,
"upload_time": "2025-10-23T23:12:14",
"upload_time_iso_8601": "2025-10-23T23:12:14.659635Z",
"url": "https://files.pythonhosted.org/packages/cb/9c/ba5d4efe502dd46a6ee25377777e35e69487384d8164e6f2119844934958/shared_memory_lock-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a0c4b5f4702f9a131576bfb4edc83330253984bce2fcb136598a70513d07b428",
"md5": "6b82e59276028f49c926e11f203c8b7e",
"sha256": "756126938bc5d409bbaa8e9adeafe603257b7b96e974b2107341610b8201c876"
},
"downloads": -1,
"filename": "shared_memory_lock-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "6b82e59276028f49c926e11f203c8b7e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.13.7",
"size": 7089,
"upload_time": "2025-10-23T23:12:15",
"upload_time_iso_8601": "2025-10-23T23:12:15.796309Z",
"url": "https://files.pythonhosted.org/packages/a0/c4/b5f4702f9a131576bfb4edc83330253984bce2fcb136598a70513d07b428/shared_memory_lock-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-23 23:12:15",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "shared_memory_lock"
}