=======================
Python distributed lock (currently only with memcached)
How to configure
------------------------
In your setup file (in django, settings.py), configure locking:
```python
import distributedlock
distributedlock.DEFAULT_MEMCACHED_CLIENT = memcache.Client(['127.0.0.1:11211'])
distributedlock.DEFAULT_TIMEOUT=60
distributedlock.DEFAULT_BLOCKING=False
```
If you setting up memcached in Django, you can use it abstraction of memcached.
```python
from django.core.cache import cache
distributedlock.DEFAULT_MEMCACHED_CLIENT = cache
```
You can configure this settings in each lock, as parameter.
How to use
------------------------
Using minimal configuration, as decorator:
```python
from distributedlock import distributedlock
@distributedlock()
def hello_world():
print 'running'
```
Or as `with` block:
```python
from distributedlock import distributedlock
#... my code before
with distributedlock('hello'):
print 'running'
#... my code after
```
You can use with conventional threading.Lock (only in process locking)
```python
import threading
with distributedlock('hello', lock=threading.Lock())
print 'running'
```
Arguments
------------------------
```python
def distributedlock(key, lock=None, blocking=None)
```
* key: name of key in memcached. Avoid long names, because memcached supports only 255 characters in key. Using decorator
key name will be class name + method name if not specified.
* lock: If you desire use another lock strategy, like `threading.Lock()` or `threading.RLock()`. defaults to `distributedlock.memcachedlock.MemcachedLock`
* blocking: If another process has lock, wait until have a lock or abort immediately, raising `LockNotAcquiredError`. Defaults to `distributedlock.DEFAULT_BLOCKING`
Tips
------------------------
* If you have a dynamic key, use lock with block to compose your key. For example:
```python
def synchronized_method(arg1)
with distributedlock('sync_process_%d' % arg1.id):
# do something
```
Metadata
Release files for DistributedLock 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| DistributedLock-1.2.tar.gz | 3.5 kB | Without provenance | Details |
Release files / DistributedLock-1.2.tar.gz
| Download URL | DistributedLock-1.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18fcf4127383122d0be6ea2dddc745296a13e2a9691019f3c97bc0c6b33680cd
|
|
BLAKE2b-256 checksum How to use checksums |
1e652cdd9dbc8707bd197fd8a9823b19c86f8904203363c90ba16e6f66b4bc23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for DistributedLock 1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.