Simple Lockfile System.
Project description
[](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/)
# 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
[](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/)
# 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simple_lock-1.0.6.tar.gz
(4.5 kB
view details)
Built Distributions
simple_lock-1.0.6-py3.6.egg
(8.8 kB
view details)
File details
Details for the file simple_lock-1.0.6.tar.gz
.
File metadata
- Download URL: simple_lock-1.0.6.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
f6619df3417aa7b4ae81c37f308a740d0d30ae9a13cc68dbf50e32907e5ba491
|
|
MD5 |
89e35b4e70ecb2d9e95785b84435f239
|
|
BLAKE2b-256 |
7c65df0aab01d85c6d60ee84ca5078ddf0c6778e5045cfbdfc6f3036ad823d7c
|
File details
Details for the file simple_lock-1.0.6-py3.6.egg
.
File metadata
- Download URL: simple_lock-1.0.6-py3.6.egg
- Upload date:
- Size: 8.8 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ca2bd6de5d2aa77162254fb921ab7627b0f678711639afd702bca74b885b0977
|
|
MD5 |
b6ac6e4e36e956fe67688dd44e17666a
|
|
BLAKE2b-256 |
aea2e14192194f3693a285e3f0b648abcdb79356d8ad2f0cfdd8e8b859fecb4d
|
File details
Details for the file simple_lock-1.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: simple_lock-1.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6716ab7caae23f5509730aa5b4b426d44f931ae10fa538851ae277632a21342c
|
|
MD5 |
1e75b2fee3bb017466f7f747f08a9d02
|
|
BLAKE2b-256 |
01f1fff71baebaa22e9958d9f0532b0e55c10248e4481120da5d553bd401ec0d
|