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 is False (default), it will raise Locked if the lock couldn’t be obtained.

Otherwise, if ret is True, it will simply return False 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 raising Locked.

  • 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. If ret is true then will also return False on failure.