POSIX file system locking using flock
Project description
locks
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file locks-0.1.1.tar.gz
.
File metadata
- Download URL: locks-0.1.1.tar.gz
- Upload date:
- Size: 3.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a894bcd725bb0d36613d1ccb4880d2c9c967ad8107619fad4c6a609dd70a3df0 |
|
MD5 | 0595f0298ace6535db1f1b42605e2f96 |
|
BLAKE2b-256 | 297c94a8e0b91c0b9cec5adf7cd7dc871b215835ca1ba9e3f595fee8a0fb9e49 |
File details
Details for the file locks-0.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: locks-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8053d71dc96394639ecb4358c872f186ae7a3b70b759bb00d4966dda8e208ae |
|
MD5 | ba32df81b256180d4247e7f65c0767a8 |
|
BLAKE2b-256 | 6e9ad82c0c43c1d89da8ef35a50f3266ebf4d69aaf00d94202000969c7040943 |