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 details)
Built Distribution
File details
Details for the file tmplockfile-0.0.3.tar.gz
.
File metadata
- Download URL: tmplockfile-0.0.3.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a9b639ba8f258b975111e7d9f15b0adee3fd72ac4a8b426ef1d225f0182e4e1 |
|
MD5 | 840ebb432418a6aadb076c94cc6aafcd |
|
BLAKE2b-256 | 5727e0f74ee56003fc2a8a065bdd51b89562d0494863d7ff752d710086e00763 |
File details
Details for the file tmplockfile-0.0.3-py2-none-any.whl
.
File metadata
- Download URL: tmplockfile-0.0.3-py2-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12b1d9c00f45734da8c48dd61c3c2f0f7c52bd94c2a973548eb8114ca86739d6 |
|
MD5 | 26d78c09dd10b6a4781286472668f71b |
|
BLAKE2b-256 | 18bf730b97c35311cea34674a522f42dce8924c0f7c3721bcdd99c32ff0bbc5f |