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.3
- 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.3
- 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.3.tar.gz
(2.2 kB
view hashes)
Built Distribution
Close
Hashes for tmplockfile-0.0.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12b1d9c00f45734da8c48dd61c3c2f0f7c52bd94c2a973548eb8114ca86739d6 |
|
MD5 | 26d78c09dd10b6a4781286472668f71b |
|
BLAKE2b-256 | 18bf730b97c35311cea34674a522f42dce8924c0f7c3721bcdd99c32ff0bbc5f |