(cls, *args, **kwargs)
Returns a two-tuple containing the object and its lock, which has 
        already been acquired. Once you're finished processing the object, 
        you should call release_lock() on the lock.

        Pass in a kwarg of _id to get the object with get_obj_by_id. Otherwise,
        the object will be retrieved by calling get_obj and passing it all of
        the args.

        Pass in a kwarg of create=True to create the object if it doesn't exist.
        The object will be created calling create_obj and passing it all of the
        args. If create is False or is not set, and if the object doesn't exist,
        (None, None) is returned.
Returns a two-tuple containing the object and its lock, which has 
        already been acquired. Once you're finished processing the object, 
        you should call release_lock() on the lock.
Returns a two - tuple containing the object and its lock which has already been acquired . Once you re finished processing the object you should call release_lock () on the lock .
def get_locked_obj(cls, *args, **kwargs):
        """
        Returns a two-tuple containing the object and its lock, which has 
        already been acquired. Once you're finished processing the object, 
        you should call release_lock() on the lock.

        Pass in a kwarg of _id to get the object with get_obj_by_id. Otherwise,
        the object will be retrieved by calling get_obj and passing it all of
        the args.

        Pass in a kwarg of create=True to create the object if it doesn't exist.
        The object will be created calling create_obj and passing it all of the
        args. If create is False or is not set, and if the object doesn't exist,
        (None, None) is returned.
        """
        create = kwargs.pop("create", False)
        _id = kwargs.get("_id", None)
        degrade_gracefully = kwargs.pop('degrade_gracefully', False)
        timeout_seconds = kwargs.pop('timeout_seconds', 120)

        if _id:
            lock = cls.get_obj_lock_by_id(_id, timeout_seconds=timeout_seconds)
        else:
            lock = cls.get_class_lock(timeout_seconds=timeout_seconds)

        lock = acquire_lock(lock, degrade_gracefully, blocking=True)
        try:
            if _id:
                obj = cls.get_obj_by_id(_id)
            else:
                obj = cls.get_obj(*args, **kwargs)
            if not obj:
                if create:
                    obj = cls.create_obj(*args, **kwargs)
                else:
                    release_lock(lock, degrade_gracefully)
                    return LockManager(None, None)
        except:
            release_lock(lock, degrade_gracefully)
            raise
        else:
            if _id:
                return LockManager(obj, lock)
            else:
                obj_lock = cls.get_obj_lock(obj)
                obj_lock = acquire_lock(obj_lock, degrade_gracefully)
                # Refresh the object in case another thread has updated it
                obj = cls.get_latest_obj(obj)
                release_lock(lock, degrade_gracefully)
                return LockManager(obj, obj_lock)
def get_locked_obj ( cls , * args , * * kwargs ) : create = kwargs . pop ( "create" , False ) _id = kwargs . get ( "_id" , None ) degrade_gracefully = kwargs . pop ( 'degrade_gracefully' , False ) timeout_seconds = kwargs . pop ( 'timeout_seconds' , 120 ) if _id : lock = cls . get_obj_lock_by_id ( _id , timeout_seconds = timeout_seconds ) else : lock = cls . get_class_lock ( timeout_seconds = timeout_seconds ) lock = acquire_lock ( lock , degrade_gracefully , blocking = True ) try : if _id : obj = cls . get_obj_by_id ( _id ) else : obj = cls . get_obj ( * args , * * kwargs ) if not obj : if create : obj = cls . create_obj ( * args , * * kwargs ) else : release_lock ( lock , degrade_gracefully ) return LockManager ( None , None ) except : release_lock ( lock , degrade_gracefully ) raise else : if _id : return LockManager ( obj , lock ) else : obj_lock = cls . get_obj_lock ( obj ) obj_lock = acquire_lock ( obj_lock , degrade_gracefully ) # Refresh the object in case another thread has updated it obj = cls . get_latest_obj ( obj ) release_lock ( lock , degrade_gracefully ) return LockManager ( obj , obj_lock )