Skip to main content

Run long-running work exclusively using PostgreSQL advisory locks

Project description

asyncpg-lock

Run long-running work exclusively using PostgreSQL advisory locks.

Usage

import asyncio
import asyncpg
import asyncpg_lock


async def worker_func() -> None:
    # something very long-running
    while True:
        await asyncio.sleep(100500)


async def main():
    guard = asyncpg_lock.AdvisoryLockGuard(
        connect=lambda: asyncpg.connect("postgresql://localhost/db")
    )
    # worker_func will not be executed concurrently
    key = 100500
    tasks = [
        asyncio.create_task(guard.run(key, worker_func)),
        asyncio.create_task(guard.run(key, worker_func)),
        asyncio.create_task(guard.run(key, worker_func)),
        asyncio.create_task(guard.run(key, worker_func))
    ]
    await asyncio.gather(*tasks)


asyncio.run(main())

v0.0.1 (2025-07-07)

  • Initial release

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

asyncpg_lock-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncpg_lock-0.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file asyncpg_lock-0.0.1.tar.gz.

File metadata

  • Download URL: asyncpg_lock-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for asyncpg_lock-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cac6927677535025fa16eb63e66d7d223db924ad03730efae1d66e71a78c9e02
MD5 9763d8f5e0b7d61e0aae8eb9a99003ce
BLAKE2b-256 c091ca2e6fcc7d24df57dc59c2b718e7e3d21fb6a55cdf577b219c99e56dc9c7

See more details on using hashes here.

File details

Details for the file asyncpg_lock-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: asyncpg_lock-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for asyncpg_lock-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f29e252b908d3fd06eb644f1fc026df47e3db1738ee24931e14138fb5bb9922
MD5 c7b06722b22f2146d91d2cb57101ae7e
BLAKE2b-256 0aff4b506c0aa62244019df5e073cd4de057749c05bc65e2a2d3c8f105097004

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page