MCPcopy
hub / github.com/OpenHands/OpenHands / refresh_lock_periodically

Function refresh_lock_periodically

openhands/app_server/utils/redis_lock.py:36–53  ·  view source on GitHub ↗

Keep a Redis lock alive by refreshing its TTL every *interval* seconds. Intended to run as a background task (via ``asyncio.create_task``) alongside a long-running operation. Cancel the task when the operation finishes; the caller is responsible for releasing the lock afterwards.

(lock: Lock, interval: int)

Source from the content-addressed store, hash-verified

34
35
36async def refresh_lock_periodically(lock: Lock, interval: int) -> None:
37 """Keep a Redis lock alive by refreshing its TTL every *interval* seconds.
38
39 Intended to run as a background task (via ``asyncio.create_task``) alongside
40 a long-running operation. Cancel the task when the operation finishes; the
41 caller is responsible for releasing the lock afterwards.
42 """
43 try:
44 while True:
45 await asyncio.sleep(interval)
46 try:
47 await lock.reacquire()
48 except LockError:
49 _logger.warning(
50 'redis_lock:periodic_refresh_failed', extra={'key': lock.name}
51 )
52 except asyncio.CancelledError:
53 pass

Callers 1

streamMethod · 0.90

Calls 2

reacquireMethod · 0.80
warningMethod · 0.80

Tested by

no test coverage detected