betty.concurrent module

Provide utilities for concurrent programming.

class betty.concurrent.AsynchronizedLock[source]

Bases: _Lock

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

Parameters:

lock (_thread.allocate_lock)

__init__(lock: _thread.allocate_lock)[source]
Parameters:

lock (_thread.allocate_lock)

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

Acquire the lock.

Parameters:

wait (bool)

Return type:

bool

release() None[source]

Release the lock.

Return type:

None

classmethod threading() Self[source]

Create a new thread-safe, asynchronous lock.

Return type:

typing.Self

class betty.concurrent.MultiLock[source]

Bases: _Lock

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

Parameters:

locks (betty.concurrent._Lock)

__init__(*locks: betty.concurrent._Lock)[source]
Parameters:

locks (betty.concurrent._Lock)

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

Acquire the lock.

Parameters:

wait (bool)

Return type:

bool

release() None[source]

Release the lock.

Return type:

None

class betty.concurrent.RateLimiter[source]

Bases: object

Rate-limit operations.

This class implements the Token Bucket algorithm.

This class is thread-safe.

Parameters:

maximum (int)

__init__(maximum: int)[source]
Parameters:

maximum (int)

async wait() None[source]

Wait until an operation may be performed (again).

Return type:

None

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

Acquire a synchronous lock asynchronously.

Parameters:
  • lock (_thread.allocate_lock)

  • wait (bool)

Return type:

bool