betty.concurrent module

Provide utilities for concurrent programming.

final class betty.concurrent.AsynchronizedLock[source]

Bases: _Lock

Make a sychronous (blocking) lock asynchronous (non-blocking).

__init__(lock: allocate_lock)[source]
async acquire(*, wait: bool = True) bool[source]

Acquire the lock.

release() None[source]

Release the lock.

classmethod threading() Self[source]

Create a new thread-safe, asynchronous lock.

final class betty.concurrent.MultiLock[source]

Bases: _Lock

Provide a lock that only acquires if all of the given locks can be acquired.

__init__(*locks: _Lock)[source]
async acquire(*, wait: bool = True) bool[source]

Acquire the lock.

release() None[source]

Release the lock.

final class betty.concurrent.RateLimiter[source]

Bases: object

Rate-limit operations.

This class implements the Token Bucket algorithm.

This class is thread-safe.

__init__(maximum: int)[source]
async wait() None[source]

Wait until an operation may be performed (again).

async betty.concurrent.asynchronize_acquire(lock: allocate_lock, *, wait: bool = True) bool[source]

Acquire a synchronous lock asynchronously.