prefect.locking.memory

Classes

MemoryLockManager

A lock manager that stores lock information in memory. Note: because this lock manager stores data in memory, it is not suitable for use in a distributed environment or across different processes. Methods:

aacquire_lock

aacquire_lock(self, key: str, holder: str, acquire_timeout: float | None = None, hold_timeout: float | None = None) -> bool

aacquire_lock

aacquire_lock(self, key: str, holder: str, acquire_timeout: Optional[float] = None, hold_timeout: Optional[float] = None) -> bool
Acquire a lock for a transaction record with the given key. Will block other actors from updating this transaction record until the lock is released. Args:
  • key: Unique identifier for the transaction record.
  • holder: Unique identifier for the holder of the lock.
  • acquire_timeout: Max number of seconds to wait for the record to become available if it is locked while attempting to acquire a lock. Pass 0 to attempt to acquire a lock without waiting. Blocks indefinitely by default.
  • hold_timeout: Max number of seconds to hold the lock for. Holds the lock indefinitely by default.
Returns:
  • True if the lock was successfully acquired; False otherwise.

acquire_lock

acquire_lock(self, key: str, holder: str, acquire_timeout: float | None = None, hold_timeout: float | None = None) -> bool

acquire_lock

acquire_lock(self, key: str, holder: str, acquire_timeout: Optional[float] = None, hold_timeout: Optional[float] = None) -> bool
Acquire a lock for a transaction record with the given key. Will block other actors from updating this transaction record until the lock is released. Args:
  • key: Unique identifier for the transaction record.
  • holder: Unique identifier for the holder of the lock.
  • acquire_timeout: Max number of seconds to wait for the record to become available if it is locked while attempting to acquire a lock. Pass 0 to attempt to acquire a lock without waiting. Blocks indefinitely by default.
  • hold_timeout: Max number of seconds to hold the lock for. Holds the lock indefinitely by default.
Returns:
  • True if the lock was successfully acquired; False otherwise.

await_for_lock

await_for_lock(self, key: str, timeout: float | None = None) -> bool

await_for_lock

await_for_lock(self, key: str, timeout: Optional[float] = None) -> bool
Wait for the corresponding transaction record to become free. Args:
  • key: Unique identifier for the transaction record.
  • timeout: Maximum time to wait. None means to wait indefinitely.
Returns:
  • True if the lock becomes free within the timeout; False otherwise.

is_lock_holder

is_lock_holder(self, key: str, holder: str) -> bool

is_lock_holder

is_lock_holder(self, key: str, holder: str) -> bool
Check if the current holder is the lock holder for the transaction record. Args:
  • key: Unique identifier for the transaction record.
  • holder: Unique identifier for the holder of the lock.
Returns:
  • True if the current holder is the lock holder; False otherwise.

is_locked

is_locked(self, key: str) -> bool

is_locked

is_locked(self, key: str) -> bool
Simple check to see if the corresponding record is currently locked. Args:
  • key: Unique identifier for the transaction record.
Returns:
  • True is the record is locked; False otherwise.

release_lock

release_lock(self, key: str, holder: str) -> None

release_lock

release_lock(self, key: str, holder: str) -> None
Releases the lock on the corresponding transaction record. Args:
  • key: Unique identifier for the transaction record.
  • holder: Unique identifier for the holder of the lock. Must match the holder provided when acquiring the lock.

wait_for_lock

wait_for_lock(self, key: str, timeout: float | None = None) -> bool

wait_for_lock

wait_for_lock(self, key: str, timeout: Optional[float] = None) -> bool
Wait for the corresponding transaction record to become free. Args:
  • key: Unique identifier for the transaction record.
  • timeout: Maximum time to wait. None means to wait indefinitely.
Returns:
  • True if the lock becomes free within the timeout; False otherwise.