Do multiple lock attempts
This commit is contained in:
parent
88556f4a33
commit
42c5f84ba7
|
@ -128,14 +128,34 @@ def writedata(zk_conn, kv):
|
||||||
|
|
||||||
# Write lock function
|
# Write lock function
|
||||||
def writelock(zk_conn, key):
|
def writelock(zk_conn, key):
|
||||||
lock_id = str(uuid.uuid1())
|
while True:
|
||||||
lock = zk_conn.WriteLock('{}'.format(key), lock_id)
|
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
|
return lock
|
||||||
|
|
||||||
# Read lock function
|
# Read lock function
|
||||||
def readlock(zk_conn, key):
|
def readlock(zk_conn, key):
|
||||||
lock_id = str(uuid.uuid1())
|
while True:
|
||||||
lock = zk_conn.ReadLock('{}'.format(key), lock_id)
|
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
|
return lock
|
||||||
|
|
||||||
# Exclusive lock function
|
# Exclusive lock function
|
||||||
|
@ -151,5 +171,6 @@ def exclusivelock(zk_conn, key):
|
||||||
if count > 5:
|
if count > 5:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
time.sleep(0.5)
|
||||||
continue
|
continue
|
||||||
return lock
|
return lock
|
||||||
|
|
Loading…
Reference in New Issue