Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0h-n0/simple-lock
https://github.com/0h-n0/simple-lock
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/0h-n0/simple-lock
- Owner: 0h-n0
- License: mit
- Created: 2018-06-11T09:43:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-25T19:39:00.000Z (about 6 years ago)
- Last Synced: 2024-11-09T09:49:09.344Z (3 months ago)
- Language: Python
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/0h-n0/simple-lock)
[](https://github.com/0h-n0/simple-lock)
[](https://badge.fury.io/py/simple-lock)
[](https://travis-ci.org/0h-n0/simple-lock)
[](https://codecov.io/gh/0h-n0/simple-lock)
[](https://codeclimate.com/github/0h-n0/simple-lock/maintainability)
[](https://bettercodehub.com/)
[](https://github.com/0h-n0/simple-lock)# simple-lock
simple-lock provides lock system as a decorator or with-statement in your code. It is easy to use them.
## Concept
You can easily implement lock system in your application with modifing a few line. There are mainly two decorator in `simple_lock`. First, `simple_lock.lock` locks function and create a lockfile. After that, other functions refer to the lockfile can't be executed normally. Second, without creating a new lockfile, `simple_lock.watch` watchs a lockfile provieded as one of arguments without creating a new lockfile.
## Instalation
```shell
$ pip install simple-lock
```## How to use
### Lock your function with `simple_lock.lock` decorator.
When a funciton try to create a lockfile and the lockfile already exists. `simple_lock.lock` decorator returns `return_value` like the following codes.
```test.py
from simple_lock import lock
@lock(filename='simple.lock', path='~/locks',
return_value=10)
def sleep():
import time
time.sleep(10)
sleep() # -> 10
```You can provide a function as 'return_value' argument and arguments of 'return_value'.
```test.py
from simple_lock import lock
def add(a, b):
return a + b@lock(filename='simple.lock', path='~/locks',
return_value=add
a=1, b=1)
def sleep():
import time
time.sleep(10)
sleep() # -> 2
````simple_lock.watch` also provides functions similar to `simple_lock.lock`. The difference between `simple_lock.lock` and `simple_lock.watch` is just whether lockfile is created or not.
```test.py
from simple_lock import watch
@watch(filename='simple.lock', path='~/locks',
return_value=10)
def sleep():
import time
time.sleep(10)
sleep() # -> 10
``````test.py
from simple_lock import watch
def add(a, b):
return a + b@watch(filename='simple.lock', path='~/locks',
return_value=add,
a=1, b=1)
def sleep():
import time
time.sleep(10)
sleep() # -> 2
```## References
* https://github.com/benediktschmitt/py-filelock