Skip to main content

Robust file-based semaphore with stale lock recovery and context manager support.

Project description

LockFileSemaphore

A production-grade file-based semaphore to control concurrent access to shared resources across multiple processes or machines.

Includes atomic lock creation, stale lock recovery, timeout handling, and context manager support.

Installation

pip install LockFileSemaphore

Example Usage

Traditional style:

from LockFileSemaphore import begin_semaphore_ops, end_semaphore_ops

lock_id = begin_semaphore_ops("/tmp/resource.lock") #put path to lock file here , may be arbitrary
try:
    # Critical section
    pass
finally:
    end_semaphore_ops("/tmp/resource.lock", lock_id)

Context Manager style:

from LockFileSemaphore import FileLock

with FileLock("/tmp/resource.lock"): #put path to lock file here, may be arbitrary
    # Critical section
    pass

Features

  • Atomic file lock creation (O_CREAT | O_EXCL)
  • Stale lock detection and automatic cleanup
  • Timeout and retry interval configuration
  • Context manager support
  • Cross-platform compatibility

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

lockfilesemaphore-3.0.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

lockfilesemaphore-3.0.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file lockfilesemaphore-3.0.2.tar.gz.

File metadata

  • Download URL: lockfilesemaphore-3.0.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for lockfilesemaphore-3.0.2.tar.gz
Algorithm Hash digest
SHA256 81900a030129bc4ec1bf73859497c998c6ab08e15600219e18dc43bb91ba6fb6
MD5 aad555a12d37317ce94beedb179980e1
BLAKE2b-256 103740c0187fffaf1b3269b4c87ca88b9c52ab4dd7db4dd38ac78103432cf1bf

See more details on using hashes here.

File details

Details for the file lockfilesemaphore-3.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for lockfilesemaphore-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 972f31e2aa18d44835f0f839f34649b3f769a30dd5a61064599b59572c410732
MD5 a5ab105527e776d77cb3533af2b4e710
BLAKE2b-256 15cc856d2ca2bb84e533483caab003a226aa8fad9158a8b792f4f9636e4ec0a9

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