Skip to main content
[![LICENCE](https://img.shields.io/badge/LICENCE-MIT-brightgreen.svg)](https://github.com/0h-n0/simple-lock)
[![PYTHON version](https://img.shields.io/badge/python-3.5,3.6-blue.svg)](https://github.com/0h-n0/simple-lock)
[![PyPI version](https://img.shields.io/pypi/v/simple-lock.svg)](https://badge.fury.io/py/simple-lock)
[![Build Status](https://travis-ci.org/0h-n0/simple-lock.svg?branch=master)](https://travis-ci.org/0h-n0/simple-lock)
[![codecov](https://codecov.io/gh/0h-n0/simple-lock/branch/master/graph/badge.svg)](https://codecov.io/gh/0h-n0/simple-lock)
[![Maintainability](https://api.codeclimate.com/v1/badges/9a8b4b39d3673ccb6db6/maintainability)](https://codeclimate.com/github/0h-n0/simple-lock/maintainability)
[![BCH compliance](https://bettercodehub.com/edge/badge/0h-n0/simple-lock?branch=master)](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

Metadata

Release files for simple-lock 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-lock 1.0.6
File Size Uploaded
simple_lock-1.0.6.tar.gz 4.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for simple-lock 1.0.6
File Interpreter ABI Platform
simple_lock-1.0.6-py3.6.egg Legacy Egg format - - Details
simple_lock-1.0.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 18.6 kB

Release files / simple_lock-1.0.6.tar.gz

Download URL simple_lock-1.0.6.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f6619df3417aa7b4ae81c37f308a740d0d30ae9a13cc68dbf50e32907e5ba491
BLAKE2b-256 checksum
How to use checksums
7c65df0aab01d85c6d60ee84ca5078ddf0c6778e5045cfbdfc6f3036ad823d7c
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / simple_lock-1.0.6-py3.6.egg

Download URL simple_lock-1.0.6-py3.6.egg
Size 8.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
ca2bd6de5d2aa77162254fb921ab7627b0f678711639afd702bca74b885b0977
BLAKE2b-256 checksum
How to use checksums
aea2e14192194f3693a285e3f0b648abcdb79356d8ad2f0cfdd8e8b859fecb4d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / simple_lock-1.0.6-py2.py3-none-any.whl

Download URL simple_lock-1.0.6-py2.py3-none-any.whl
Size 5.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6716ab7caae23f5509730aa5b4b426d44f931ae10fa538851ae277632a21342c
BLAKE2b-256 checksum
How to use checksums
01f1fff71baebaa22e9958d9f0532b0e55c10248e4481120da5d553bd401ec0d
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.6 This release

3 release files

1.0.5

1 release file

1.0.4

3 release files

1.0.3

3 release files

1.0.1

2 release files

1.0.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page