Lockpick
Lockpick is an utility for distributed locking using zookeeper. Its intended to be used in distributed environments where scripts need synchronization between runs.
Why Lockpick
Lockpick uses the kazoo library but provides following benefits over kazoo recipes :
- Use non ephemeral zknode to allow explicit lock release
- Exits with correct return codes
- Correct signal Handling and cleanup
- Retires and timeout
Usage
$ lockpick --help
usage: lockpick [-h] [-s SERVERS] [-c CHROOT] [-i IDENTIFIER] [-v]
[-r RETRY_COUNT] [-p RETRY_SLEEP]
{lock,rlock,wlock,unlock,list} lock_path
Distributed locking using Zookeeper primarily for scripting. After acquiring
the lock, the zk node is printed to STDOUT. This zk node should be passed to
unlock. Note: all logs are printed to STDERR
positional arguments:
{lock,rlock,wlock,unlock,list}
lock: acquire a mutex lock. rlock: acquire a read lock
wlock: acquire a write lock. unlock: release lock
identified by zk node. list: list all lock contenders
lock_path ZK path to lock OR ZK node to unlock. For the
unlockaction this must be the chrooted zk path to the
node e.g.lockpick lock -c /devops /mylocklockpick
unlock -c /devops /mylock/9d2badeec7684f35b10f4860db42
e45c__rlock__0000000022
optional arguments:
-h, --help show this help message and exit
-s SERVERS, --servers SERVERS
-c CHROOT, --chroot CHROOT
ZK chroot for the lock path
-i IDENTIFIER, --identifier IDENTIFIER
Optional string identifier to add to the lock node OR
verify when unlocking
-v, --verbose
-r RETRY_COUNT, --retry-count RETRY_COUNT
-p RETRY_SLEEP, --retry-sleep RETRY_SLEEP
Install
We recommend using pip to install in a virtualenv :
$ virtualenv lockpick
$ pip install lockpick
Example
$ lockpick -s localhost:2181 -c /test -i "test lock1" rlock /mylock
/mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038
$ lockpick -s localhost:2181 -c /test -i "test lock1" rlock /mylock
/mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039
$ lockpick -s localhost:2181 -c /test -i "test lock1" list /mylock
'test lock1' /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039
'test lock1' /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038
$ lockpick -s localhost:2181 -c /test -i "test lock1" wlock /mylock
[2018-07-25 19:09:53,095] WARNING lockpick: Waiting to acquire lock, contenders are :
[2018-07-25 19:09:53,103] WARNING lockpick: 'test lock1' /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039
[2018-07-25 19:09:53,103] WARNING lockpick: 'test lock1' /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038
[2018-07-25 19:09:53,104] WARNING lockpick: 'test lock1' /mylock/492b4a6c1727417daf511b343d0d11b7__lock__0000000042
[2018-07-25 19:09:56,104] WARNING lockpick: Waiting to acquire lock, contenders are :
[2018-07-25 19:09:56,114] WARNING lockpick: 'test lock1' /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039
[2018-07-25 19:09:56,114] WARNING lockpick: 'test lock1' /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038
[2018-07-25 19:09:56,114] WARNING lockpick: 'test lock1' /mylock/492b4a6c1727417daf511b343d0d11b7__lock__0000000042
[2018-07-25 19:09:59,116] WARNING lockpick: LockTimeout exception rasied by locker thread
[2018-07-25 19:09:59,117] ERROR lockpick: Failed to acquire lock within timeout!
$ lockpick -s localhost:2181 -c /test -i "test lock1" unlock /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038
$ lockpick -s localhost:2181 -c /test -i "test lock1" unlock /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039
$ lockpick -s localhost:2181 -c /test -i "test lock1" wlock /mylock
/mylock/d6602d4a54124826b27c50a43ab67a5e__lock__0000000043
syncd_spawn.sh
Spawns the given command only if it can acquire the given lock.
./syncd_spawn -n /test -C 'test' -l rlock sleep 5
Got lock on /test
Running your command sleep 5
Unlocked '/test/141bcfad04c6459591164ea12d1604af__rlock__0000000011'
Metadata
Release files for lockpick 1.0.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 | Actions |
|---|---|---|---|---|
| lockpick-1.0.2.tar.gz | 4.9 kB | Without provenance | Details for lockpick-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lockpick-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for lockpick-1.0.2-py3-none-any.whl |
Total release size: 10.9 kB
Release files / lockpick-1.0.2.tar.gz
| Download URL | lockpick-1.0.2.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0a3476162b0d651505dc9592b74b303a208e9085a72101c6433cf7607ae2f20
|
|
BLAKE2b-256 checksum How to use checksums |
aa0809f06eb00e2f4214a016e0e3b495ffba4018c5f2872337e58371c4499409
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
|
Release files / lockpick-1.0.2-py3-none-any.whl
| Download URL | lockpick-1.0.2-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16faffb1cc735ae3bbac95aff4066d81c427aa53ea4cc57222c29058a62d25ae
|
|
BLAKE2b-256 checksum How to use checksums |
0f08a79e8ce241edbf7d7b2faffb142d5c6431df6511d03ea47ebbbd65c8143f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
|
Security for lockpick 1.0.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.