Skip to main content

POSIX file system locking using flock

Project description

locks

PyPI version Build status

POSIX file system locking using flock.

Getting started

Install this package with

pip install locks

Usage

The simplest usage is to block indefinitely until the lock is acquired

from locks import Mutex

with Mutex('/tmp/file.lock'):
    # do exclusive stuff here

Alternatively, block until a timeout is reached

from locks import Mutex

try:
    with Mutex('/tmp/file.lock', timeout=0.5):
        # do exclusive stuff here
except BlockingIOError:
    # handle the failure to acquire the lock

Finally, a common paradigm is to attempt to acquire the lock without blocking, do something, and then block indefinitely. Here callback will be called once if we cannot immediately acquire the lock, and then we will block indefinitely.

def callback():
    print("Blocking: waiting for file lock on '/tmp/file.lock'")

with Mutex('/tmp/file.lock', callback=callback):
    # do exclusive stuff here

If both callback and timeout are used then we will attempt to acquire the lock until the timeout is reached, and then we will block indefinitely.

License

This project is licensed under the MIT License. See the LICENSE file.

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

locks-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

locks-0.1.0-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file locks-0.1.0.tar.gz.

File metadata

  • Download URL: locks-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for locks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb5385d900db600e1e106fb91aa078cdc8a753ba1eae52415988ceb81ce32391
MD5 73cefd94b9a976de396c326d3ead9721
BLAKE2b-256 4553d4e3be9bd0a2f5a3d7e60427a446732cb99db2fa878c1ad3da22ecf908aa

See more details on using hashes here.

File details

Details for the file locks-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: locks-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for locks-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cefcbb7cacd325c860c4d6456dc2e339893b1092a50b1a32daf5a1a703f7635f
MD5 ca96ebbc2df3f3ae9740abf3b4618d08
BLAKE2b-256 6406299c4d1256a264adc78eb2e75c15bd6324728ec156d4d9a0af4e1943d192

See more details on using hashes here.

Supported by

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