PostgreSQL-based distributed advisory lock (sync + async).
Project description
pg-dlock
PostgreSQL advisory-lock based distributed lock, sync + async.
from pg_dlock import Locker
with Locker("postgres://...") as locker:
with locker.lock("my-key"):
... # critical section
Async:
from pg_dlock import AsyncLocker
async with AsyncLocker("postgres://...") as locker:
async with locker.lock("my-key"):
...
API
Locker(conninfo, *, pool_min_size=0, pool_max_size=10)locker.lock(key, *, scope="session"|"transaction", shared=False) -> Locklock.try_acquire(timeout=None) -> booltimeout=None: block forevertimeout=0: non-blockingtimeout>0(seconds): wait up to N seconds (usesstatement_timeout)
lock.release()- Context manager support (
with lock:/async with lock:).
Scopes
session: each lock opens its own dedicated connection (autocommit). Released viapg_advisory_unlock.transaction: connection is checked out from an internal pool and a transaction is begun; lock is released by the commit/rollback on exit.
Keys
str/bytes: hashed withxxhash.xxh3_64into a signed int64.int: used directly (must fit in signed int64).tuple[int, int]: each element must fit in signed int32; packed into a single int64.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pg_dlock-0.0.0a0.tar.gz
(8.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pg_dlock-0.0.0a0.tar.gz.
File metadata
- Download URL: pg_dlock-0.0.0a0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b98e4d46179f19ac30de217f7aca86ee3cdcf4d0c989194027086c13034931ef
|
|
| MD5 |
4995fde783f9238ff52fba21a4101bee
|
|
| BLAKE2b-256 |
21ba80c36b8bc37178ee7331dbf39551983e21b06b904bcf994a86b021b50a56
|
File details
Details for the file pg_dlock-0.0.0a0-py3-none-any.whl.
File metadata
- Download URL: pg_dlock-0.0.0a0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de9b517ae39945d61fa5bd09e6672ecfb9a77d5e8ff2884fb650f3167299f8fc
|
|
| MD5 |
9173fb050606de2061cf265f5a0a5099
|
|
| BLAKE2b-256 |
1ba88b27aed47732493d7a4384025397dacb4c53171335ee1db6741045d03bba
|