betty.concurrent module - Betty 0.4.0a3 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.concurrent module

Provide utilities for concurrent programming.

final class betty.concurrent.AsynchronizedLock

  Bases: `_Lock`

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

  Parameters:

    lock (`_thread.allocate_lock`)

  __init__(lock: _thread.allocate_lock)
    Parameters:

      lock (`_thread.allocate_lock`)

  async acquire(*, wait: bool = True) → bool

    Acquire the lock.

    Parameters:

      wait (`bool`)

    Return type:

      `bool`

  release() → None

    Release the lock.

    Return type:

      `None`

  classmethod threading() → Self

    Create a new thread-safe, asynchronous lock.

    Return type:

      `typing.Self`

final class betty.concurrent.MultiLock

  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)
    Parameters:

      locks (`betty.concurrent._Lock`)

  async acquire(*, wait: bool = True) → bool

    Acquire the lock.

    Parameters:

      wait (`bool`)

    Return type:

      `bool`

  release() → None

    Release the lock.

    Return type:

      `None`

final class betty.concurrent.RateLimiter

  Bases: `object`

  Rate-limit operations.

  This class implements the Token Bucket algorithm.

  This class is thread-safe.

  Parameters:

    maximum (`int`)

  __init__(maximum: int)
    Parameters:

      maximum (`int`)

  async wait() → None

    Wait until an operation may be performed (again).

    Return type:

      `None`

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

  Acquire a synchronous lock asynchronously.

  Parameters:

    - lock (`_thread.allocate_lock`)

    - wait (`bool`)

  Return type:

    `bool`