renew¶
-
LockMgr.
renew
(lock: Union[str, lockmgr.models.Lock] = None, expires: int = 120, add_time: bool = True, **kwargs) → lockmgr.models.Lock[source]¶ Add
expires
seconds to the lock expiry time oflock
. Iflock
isn’t specified, will default to the class instance’s original lockmain_lock
Alias for
renew_lock()
- but withadd_time
andcreate
set toTrue
by default, instead ofFalse
.With no arguments specified, this method will renew the main lock of the class
main_lock
for an additional 2 minutes (or if the lock is already expired, will re-create it with 2 min expiry).Example usage:
>>> with LockMgr('mylock', expires=30) as l: ... sleep(10) ... l.renew(expires=60) # Add 60 seconds more time to 'mylock' expiration ... l.main_lock.refresh_from_db() ... print(l.main_lock.expires_seconds) # Output: 79 ... l.renew('lockx', expires=60) # Add 60 seconds more time to 'lockx' expiration
- Parameters
lock (Lock) – Name of the lock to renew
lock – A
Lock
object to renewexpires (int) – (Default: 120) If not add_time, then this is the new expiration time in seconds from now. If add_time, then this many seconds will be added to the expiration time of the lock.
add_time (bool) – (Default:
True
) If True, thenexpires
seconds will be added to the existing lock expiration time, instead of setting the expiration time tonow + expires
Extra Keyword Arguments
- Key bool create
(Default:
True
) If True, then create a new lock if it doesn’t exist / already expired- Key str locked_by
(Default: system hostname) What server/app is trying to obtain this lock?
- Key int lock_process
(Optional) The process ID requesting the lock
Exceptions
- Raises
LockNotFound – Raised if the requested
lock
doesn’t exist / is already expired andcreate
is False.- Return Lock lock
The
Lock
object which was renewed