MemoryLock

Lock used to synchronize the execution of a process using shared memory.

Implements: Lock

Description

The MemoryLock class is used to synchronize the execution of a process using shared memory.

Important points

  • This implementation is not suitable for synchronization of distributed processes.

Configuration parameters

options:

  • retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)

Instance methods

release_lock

Releases previously acquired lock by its key.

release_lock(context: Optional[IContext], key: str)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • key: str - a unique lock key to release.

try_acquire_lock

Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result.

try_acquire_lock(context: Optional[IContext], key: str, ttl: int): bool

  • context: IContext - (optional) a context to trace execution through a call chain.
  • key: str - a unique lock key to acquire.
  • ttl: int - a lock timeout (time to live) in milliseconds.
  • returns: bool - lock result

Examples

lock = MemoryLock()
lock.acquire_lock("123", "key1", None, None)
# processing
lock.release_lock("123", "key1")

See also