title: README author: Jan-Michael Rye
Synopsis
A context manager for rudimentary file locking. Lock files are generated next to the target path using the current hostname, process ID (PID) and a random hexadecimal token. Access to the file is then granted in order of ascending modification times of the associated lock files. If two or more lock files for the same path have the same modification time, access is granted in the sort order of the lock file paths. Each context waits for its turn to access the file.
The associated lock file is deleted on exit from the context. The context also automatically deletes dead lock files for non-existent processes on the same host. Dead locks are detected by checking if the associated process has exited with psutil.
Links
Usage
from simple_file_lock import FileLock
# ...
# Gain exclusive access to a path by creating a context with FileLock:
with FileLock(path):
# Do whatever you want with the file here. When the context is exited, the
# lock is released.
FileLock also accepts an interval parameter to configure the polling interval when waiting for existing locks to be released.
The Sphinx-generated API documentation is available here.
Unit Tests
Some basic unit tests have been implemented and can be run in a virtual environment with test.sh.
Release files for simple-file-lock 2024.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple_file_lock-2024.1.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_file_lock-2024.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.6 kB
Release files / simple_file_lock-2024.1.tar.gz
| Download URL | simple_file_lock-2024.1.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35441b77b71a6ab41e94a8814d872e53b686f6837463750e71dab1f3e4f6faa6
|
|
BLAKE2b-256 checksum How to use checksums |
43ac961569abf6af147f5e476ea96ec5870f92ed0e1231dda640db8784039a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Release files / simple_file_lock-2024.1-py3-none-any.whl
| Download URL | simple_file_lock-2024.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f5804e64d3e9833dd0a3ff7d1939cb7e7233de740ef6eb37b165ff96fd9df93d
|
|
BLAKE2b-256 checksum How to use checksums |
06260c759bd75b651431b498514c7380def36c4a25f4d123f0f39e1b70558669
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|