Do multiple lock attempts

This commit is contained in:
Joshua Boniface 2020-10-21 11:17:06 -04:00
parent 88556f4a33
commit 42c5f84ba7
1 changed files with 25 additions and 4 deletions

View File

@ -128,14 +128,34 @@ def writedata(zk_conn, kv):
# Write lock function
def writelock(zk_conn, key):
lock_id = str(uuid.uuid1())
lock = zk_conn.WriteLock('{}'.format(key), lock_id)
while True:
try:
lock_id = str(uuid.uuid1())
lock = zk_conn.WriteLock('{}'.format(key), lock_id)
break
except Exception:
count += 1
if count > 5:
break
else:
time.sleep(0.5)
continue
return lock
# Read lock function
def readlock(zk_conn, key):
lock_id = str(uuid.uuid1())
lock = zk_conn.ReadLock('{}'.format(key), lock_id)
while True:
try:
lock_id = str(uuid.uuid1())
lock = zk_conn.ReadLock('{}'.format(key), lock_id)
break
except Exception:
count += 1
if count > 5:
break
else:
time.sleep(0.5)
continue
return lock
# Exclusive lock function
@ -151,5 +171,6 @@ def exclusivelock(zk_conn, key):
if count > 5:
break
else:
time.sleep(0.5)
continue
return lock