Skip to main content

Distributed ticket lock client

Project description

Ticketing - Distributed Ticket Lock Client

An asyncio client for a network distributed lock ("ticket") service. Acquire a named lock with a wait budget and a lease, get a monotonic fencing token, run your critical section, then release.

Document

Support Platform

Install

pip install ticketing

Usage

import asyncio
from saro_ticketing import TicketBroker


async def main():
    broker = TicketBroker.connect("127.0.0.1:5225", "127.0.0.1:5226")
    try:
        await broker.wait_ready(5)

        ticket = await broker.acquire("order-42", wait=5, lease=30)
        try:
            # ... critical section, guarded by ticket.token at the resource ...
            print("token:", ticket.token)
        finally:
            await ticket.release()
    finally:
        broker.close()


asyncio.run(main())

wait and lease accept either a number of seconds or a datetime.timedelta. wait=0 waits indefinitely; the server enforces the wait, so giving up never strands a lock. The lease is the safety net that frees the lock if this client dies without releasing.

A Ticket is also an async context manager, releasing on exit:

async with await broker.acquire("order-42", wait=5, lease=30) as ticket:
    ...  # critical section

Notes

  • One address is held with two connections to the same node; two or more addresses form a cluster the broker fails over between.
  • Everything runs on a single event loop, so the client keeps no locks of its own — a coroutine holds the loop across the read-modify-write of its internal state.

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

ticketing-0.0.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

ticketing-0.0.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file ticketing-0.0.2.tar.gz.

File metadata

  • Download URL: ticketing-0.0.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ticketing-0.0.2.tar.gz
Algorithm Hash digest
SHA256 72218e34ae8d166551e733334bde85756aec9eab1b2a9e4bdf8fcbc31a0f019a
MD5 4f078d2d055c31c241ac7e1cc13dd485
BLAKE2b-256 2211b4ea2dab5bb63cf905849a64686d91f58e7647f5b696d136fe82e5be6286

See more details on using hashes here.

File details

Details for the file ticketing-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ticketing-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ticketing-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e4eb1689589e0cce24118aadfd72168f6e45f6ac075bda9066f9bc5780c5c43a
MD5 da1617b123009994d1cfb448d4d38cb1
BLAKE2b-256 e960addfa465fa9b98be2377c8172a01e6dd2dc219e8d9d0f270529d4e6745c6

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