A minimal lock file mechanism
Project description
A minimal, no-dependencies lock file mechanism, creating a temporary file to signal that a
specific file should not be touched by other scripts, or instances of the same script.
Created for [Europe 1° Warmer](https://www.onedegreewarmer.eu/).
This is module does _not_ implement OS level file locking. For that, see e.g. the built-in [lockfile](https://pythonhosted.org/lockfile/lockfile.html) module, [zc.lockfile](https://pypi.org/project/zc.lockfile/), or other similar projects.
## Installation
```sh
pip install tmplockfile
```
## Usage
```python3
from tmplockfile import LockFile, ResourceLocked
with LockFile("data.csv") as lockfile:
# Do things involving data.csv here
#
# A lock-file is temporarily placed in the same directory,
# in a way that avoids the most obvious race conditions.
# The variable `lockfile` contains the name of the lock-file,
# e.g. `data.csv~lock`.
except ResourceLocked:
print("Another script is currently working on data.csv. Try again later!")
```
## Changelog
- 0.0.2
- Don't crash when no lockfile could be created
specific file should not be touched by other scripts, or instances of the same script.
Created for [Europe 1° Warmer](https://www.onedegreewarmer.eu/).
This is module does _not_ implement OS level file locking. For that, see e.g. the built-in [lockfile](https://pythonhosted.org/lockfile/lockfile.html) module, [zc.lockfile](https://pypi.org/project/zc.lockfile/), or other similar projects.
## Installation
```sh
pip install tmplockfile
```
## Usage
```python3
from tmplockfile import LockFile, ResourceLocked
with LockFile("data.csv") as lockfile:
# Do things involving data.csv here
#
# A lock-file is temporarily placed in the same directory,
# in a way that avoids the most obvious race conditions.
# The variable `lockfile` contains the name of the lock-file,
# e.g. `data.csv~lock`.
except ResourceLocked:
print("Another script is currently working on data.csv. Try again later!")
```
## Changelog
- 0.0.2
- Don't crash when no lockfile could be created
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
tmplockfile-0.0.2.tar.gz
(2.2 kB
view hashes)
Built Distribution
Close
Hashes for tmplockfile-0.0.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ead9ff4ca060a5ad59f1283464ae491289b5ed8f7f2431d3d9d3a0c233cce73 |
|
MD5 | cdd812e586ffe49481c0e2030c715ba5 |
|
BLAKE2b-256 | afd0c69fd62ccfea8a202f6976d552ef9a87dc49bcc75cf533cba2d7039ca98a |