Claim the lock (lock must be available)
760003
def claim(self, owner, access):
        
        debuglog("%s claim(%s, %s)" % (self, owner, access.mode))
        assert owner is not None
        assert self.isAvailable(owner, access), "ask for isAvailable() first"

        assert isinstance(access, LockAccess)
        assert access.mode in ['counting', 'exclusive']
        self.waiting = [w for w in self.waiting if w[0] is not owner]
        self._addOwner(owner, access)

        debuglog(" %s is claimed '%s'" % (self, access.mode))
1048027
def release(self):
        ""
        if self.acquired_until is None:
            raise ValueError("Cannot release an unlocked lock")
        existing = float(self.redis.get(self.name) or 1)
        # if the lock time is in the future, delete the lock
        if existing >= self.acquired_until:
            self.redis.delete(self.name)
        self.acquired_until = None
834244
def _enable_lock(func):
    

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        if self.is_concurrent:
            only_read = kwargs.get('only_read')
            if only_read is None or only_read:
                with self._rwlock:
                    return func(*args, **kwargs)
            else:
                self._rwlock.acquire_writer()
                try:
                    return func(*args, **kwargs)
                finally:
                    self._rwlock.release()
        else:
            return func(*args, **kwargs)

    return wrapper
126620
def lock(self, block=True):
		
		self._locked = True
		return self._lock.acquire(block)
1035186
def _create_lock_object(self, key):
        '''
        
        '''
        return redis_lock.Lock(self.redis_conn, key,
                               expire=self.settings['REDIS_LOCK_EXPIRATION'],
                               auto_renewal=True)
724262
def lock(self):
        """"""
        try:
            self._do_lock()
            return
        except LockError:
            time.sleep(self.TIMEOUT)

        self._do_lock()
563580
private void lock(Object obtainer) throws PSQLException {
    if (lockedFor == obtainer) {
      throw new PSQLException(GT.tr("Tried to obtain lock while already holding it"),
          PSQLState.OBJECT_NOT_IN_STATE);

    }
    waitOnLock();
    lockedFor = obtainer;
  }
840236
def release(self):
		
		if self._locked is True:
			self._locked = False
			self._lock.release()
883923
def _lock(self, timeout_ms=-1):
        """"""
        vbox = VirtualBox()
        machine = vbox.find_machine(self.machine_name)
        wait_time = 0
        while True:
            session = Session()
            try:
                machine.lock_machine(session, LockType.write)
            except Exception as exc:
                if timeout_ms != -1 and wait_time > timeout_ms:
                    raise ValueError("Failed to acquire lock - %s" % exc)
                time.sleep(1)
                wait_time += 1000
            else:
                try:
                    yield session
                finally:
                    session.unlock_machine()
                break
361655
def lock(self):
        """"""
        success = self.set_status(CONST.STATUS_LOCKCLOSED_INT)

        if success:
            self._json_state['status'] = CONST.STATUS_LOCKCLOSED

        return success
372165
def acquire(self,blocking=True,timeout=None,shared=False):
        """"""
        with self._lock:
            if shared:
                self._acquire_shared(blocking,timeout)
            else:
                self._acquire_exclusive(blocking,timeout)
            assert not (self.is_shared and self.is_exclusive)
25322
def is_locked(self, key):
        
        key = str(key)
        if key in self.__variable_locks:
            return self.__variable_locks[key].locked()
        return False
1029372
def try_lock(lock):
    """"""
    # NOTE(harlowja): the keyword argument for 'blocking' does not work
    # in py2.x and only is fixed in py3.x (this adjustment is documented
    # and/or debated in http://bugs.python.org/issue10789); so we'll just
    # stick to the format that works in both (oddly the keyword argument
    # works in py2.x but only with reentrant locks).
    was_locked = lock.acquire(False)
    try:
        yield was_locked
    finally:
        if was_locked:
            lock.release()
213240
public function acquire()
    {
        if ($this->lockfp) {
            $this->log("acquire - existing lock");
            return;
        }

        $this->openLockFile();
        $this->log("acquire - try lock");
        flock($this->lockfp, LOCK_EX);
        $this->log("acquire - got lock");
    }
356445
def acquire_lock(lock_name)
      begin
        acquired = false
        sql = lock_query(lock_name)
        connection.query(sql) do |result|
          acquired = result.fetch_row.first == "1"
        end
        acquired
      rescue ::Exception
        false
      end
    end
605448
def on_lock(self, widget, data=None):
        """"""
        path_list = None
        if self.view is not None:
            model, path_list = self.tree_view.get_selection().get_selected_rows()
        models = [self.list_store[path][self.MODEL_STORAGE_ID] for path in path_list] if path_list else []
        if models:
            if len(models) > 1:
                self._logger.warning("Please select only one element to be locked.")
            try:
                self.model.global_variable_manager.lock_variable(models[0])
            except AttributeError as e:
                self._logger.warning("The respective core element of {1}.list_store couldn't be locked. -> {0}"
                                  "".format(e, self.__class__.__name__))
            return True
        else:
            self._logger.warning("Please select an element to be locked.")
1364979
def get(self, key, default):
        """"""
        with self._lock:
            try:
                return self._dict[key].copy()
            except KeyError:
                return default