Skip to content

set_ttl#

This function sets the lock time to live (in seconds). The function will return False if there is no lock with that name, otherwise it will return True. It could be useful for extending the lock's lifetime. Locks are automatically released when their TTL is exceeded without explicitly calling release.

Definition#

1
2
3
4
def set_ttl(
    self,
    ttl: int,
) -> bool

Examples#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def work(
    self,
    task,
):
    single_access_api_url = task.kwargs['single_access_api_url']

    lock = self.lock('single_access_api')
    if self.acquire(
        timeout=10,
        ttl=20,
    ):
        while True:
            result = some_api()
            if result.not_yet_available:
                lock.set_ttl(20)
            else:
                finalize(result)