def __init__(self): self.session_id = uuid.uuid1() self.session_objects_add = [] self.session_objects_delete = [] self.session_timeout = current_milli_time() + Session.max_duration self.dlm = ClusterLock() self.acquired_locks = [] self.already_saved = []
def work1(): dlm = ClusterLock() while not dlm.lock("toto", 2000): print("1> waiting for acquiring lock") time.sleep(0.1) print("1> acquired lock") time.sleep(3) dlm.unlock("toto")
return RomeSession() # return OldRomeSession() def model_query(context, *args, **kwargs): # base_model = kwargs["base_model"] # models = args return RomeQuery(*args, **kwargs) import random from nova.openstack.common import uuidutils from lib.rome.driver.redis.lock import ClusterLock as ClusterLock dlm = ClusterLock() def acquire_lock(lockname): global dlm try_to_lock = True while try_to_lock: if dlm.lock(lockname, 100): fo = open("/opt/logs/db_api.log", "a") fo.write("[NET] acquired lock: %s\n" % (lockname)) fo.close() return True def release_lock(lockname): global dlm