https://github.com/jplusplus/lockfile
A minimal lock file mechanism
https://github.com/jplusplus/lockfile
Last synced: 9 months ago
JSON representation
A minimal lock file mechanism
- Host: GitHub
- URL: https://github.com/jplusplus/lockfile
- Owner: jplusplus
- License: mit
- Created: 2019-03-27T11:45:18.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-19T13:05:22.000Z (about 7 years ago)
- Last Synced: 2025-09-21T02:27:10.868Z (9 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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