Acquire.ObjectStore._mutex module

class Mutex(key=None, timeout=10, lease_time=10, bucket=None)[source]

Bases: object

This class implements a mutex that sits in the object store. The mutex is associated with a key. A thread holds this mutex if it has successfully written its secret to this key. If not, then another thread must hold the mutex, and we have to wait…

assert_not_expired()[source]

Function that asserts that this mutex has not expired

expired()[source]

Return whether or not this lock has expired

fully_unlock()[source]

This fully unlocks the mutex, removing all levels of recursion

is_locked()[source]

Return whether or not this mutex is locked

lock(timeout=None, lease_time=None)[source]

Lock the mutex, blocking until the mutex is held, or until ‘timeout’ seconds have passed. If we time out, then an exception is raised. The lock is held for a maximum of ‘lease_time’ seconds.

seconds_remaining_on_lease()[source]

Return the number of seconds remaining on this lease. You must unlock the mutex before the lease expires, or else an exception will be raised when you unlock, and you will likely have a race condition

unlock()[source]

Release the mutex if it is held. Does nothing if the mutex is not held. If the mutex is unlocked after the lease has expired then this will raise a MutexTimeoutError. You should check for this when you unlock to make sure that you have not risked a race condition.