Add exclusive lock function

This commit is contained in:
Joshua Boniface 2020-10-21 10:46:41 -04:00
parent bae366a316
commit 3839040092
1 changed files with 16 additions and 0 deletions

View File

@ -137,3 +137,19 @@ def readlock(zk_conn, key):
lock_id = str(uuid.uuid1()) lock_id = str(uuid.uuid1())
lock = zk_conn.ReadLock('{}'.format(key), lock_id) lock = zk_conn.ReadLock('{}'.format(key), lock_id)
return lock return lock
# Exclusive lock function
def exclusivelock(zk_conn, key):
count = 1
while True:
try:
lock_id = str(uuid.uuid1())
lock = zk_conn.Lock('{}'.format(key), lock_id)
break
except Exception:
count += 1
if count > 5:
break
else:
continue
return lock