lock¶
-
LockMgr.
lock
(name, expires: int = None, ret: bool = False, wait: int = None)[source]¶ Obtains a lock using
get_lock()
and appends it to_locks
if successful.If the argument
ret
isFalse
(default), it will raiseLocked
if the lock couldn’t be obtained.Otherwise, if
ret
isTrue
, it will simply returnFalse
if the requested lock name is already locked.- Parameters
name (str) – A unique name to identify your lock
expires (int) – (Default: 600 sec) How long before this lock is considered stale and forcefully released?
ret (bool) – (Default: False) Return
False
if locked, instead of raisingLocked
.wait (int) – (Optional) Retry obtaining the lock for this many seconds. MUST be divisible by 5. If not empty, will retry obtaining the lock every 5 seconds until
wait
seconds
- Raises
Locked – If the requested lock
name
is already locked elsewhere,Locked
will be raised- Return bool success
True
if successful. Ifret
is true then will also return False on failure.