def reacquire(self) -> Awaitable[bool]: """ Resets a TTL of an already acquired lock back to a timeout value. """ if self.local.token is None: raise LockError("Cannot reacquire an unlocked lock") if self.timeout is None: raise LockError("Cannot reacquire a lock with no timeout") return self.do_reacquire()
def release(self) -> Awaitable[NoReturn]: """Releases the already acquired lock""" expected_token = self.local.token if expected_token is None: raise LockError("Cannot release an unlocked lock") self.local.token = None return self.do_release(expected_token)
def extend(self, additional_time: float, replace_ttl: bool = False) -> Awaitable[bool]: """ Adds more time to an already acquired lock. ``additional_time`` can be specified as an integer or a float, both representing the number of seconds to add. ``replace_ttl`` if False (the default), add `additional_time` to the lock's existing ttl. If True, replace the lock's ttl with `additional_time`. """ if self.local.token is None: raise LockError("Cannot extend an unlocked lock") if self.timeout is None: raise LockError("Cannot extend a lock with no timeout") return self.do_extend(additional_time, replace_ttl)
async def __aenter__(self): # force blocking, as otherwise the user would have to check whether # the lock was actually acquired or not. if await self.acquire(blocking=True): return self raise LockError("Unable to acquire lock within the time specified")
async def __aenter__(self): if await self.acquire(): return self raise LockError("Unable to acquire lock within the time specified")