Locks or unlocks the file

        :param lock: Lock or unlock the file
        :type lock: bool
        :param changelist: Optional changelist to checkout the file into
        :type changelist: :class:`.Changelist`
354293
def lock(self, lock=True, changelist=0):
        

        cmd = 'lock' if lock else 'unlock'
        if changelist:
            self._connection.run([cmd, '-c', changelist, self.depotFile])
        else:
            self._connection.run([cmd, self.depotFile])

        self.query()
793184
def lock(self):
        '''
        
        '''

        # Open file
        self.__fd = open(self.__lockfile, "w")

        # Get it locked
        if self.__locktype == "wait":
            # Try to get it locked until ready
            fcntl.flock(self.__fd.fileno(), fcntl.LOCK_EX)
        elif self.__locktype == "lock":
            # Try to get the locker if can not raise an exception
            try:
                fcntl.flock(self.__fd.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
            except IOError:
                raise AlreadyLocked("File is already locked")
435680
def assert_lock(fname):
    

    if not set_lock(fname):
        logger.error('File {} is already locked. Terminating.'.format(fname))
        sys.exit()
642989
def unlock(self, store=True):
        
        result = self._iface.ach_unlock(self.name)
        result and store and self._store()
        return result
167395
def with_lock
      @zk_lock ||= @zk.locker(current_lock_path)

      begin
        @zk_lock.lock!(true)
      rescue Exception
        # handle shutdown case
        running? ? raise : return
      end

      if running?
        @zk_lock.assert!
        yield
      end
    ensure
      if @zk_lock
        begin
          @zk_lock.unlock!
        rescue => ex
          logger.warn("Failed to release lock: #{ex.inspect}")
        end
      end
    end
1215427
def locked_blocks_iterator(blockfile, start_info=(0, 0), cached_headers=50, batch_size=50):
    
    f = blockfile
    current_state = []

    def change_state(bc, ops):
        for op, bh, work in ops:
            if op == 'add':
                current_state.append(bh)
                pass
            else:
                current_state.pop()
    bc = BlockChain()
    bc.add_change_callback(change_state)
    bhs = []
    index = 0
    info_offset = start_info
    while 1:
        v = blockfile.next_offset(info_offset)
        if v is None:
            break
        block_offset, info_offset = v
        f.jump_to(block_offset)
        bh = Block.parse_as_header(f)
        bh.info = block_offset

        bhs.append(bh)
        if len(bhs) > batch_size:
            bc.add_headers(bhs)
            bhs = []
            if len(current_state) > cached_headers:
                for bh in current_state[:cached_headers]:
                    bh.index = index
                    yield bh
                    index += 1
                    bc.lock_to_index(index)
                current_state = current_state[cached_headers:]
141223
def _safe_write_to_file(self, file, message):
        
        target = file
        lock_name = make_lock_name(target, self.outfolder)
        lock_file = self._make_lock_path(lock_name)

        while True:
            if os.path.isfile(lock_file):
                self._wait_for_lock(lock_file)
            else:
                try:
                    self.locks.append(lock_file)
                    self._create_file_racefree(lock_file)
                except OSError as e:
                    if e.errno == errno.EEXIST:
                        print ("Lock file created after test! Looping again.")
                        continue  # Go back to start

                # Proceed with file writing
                with open(file, "a") as myfile:
                    myfile.write(message + "\n")

                os.remove(lock_file)
                self.locks.remove(lock_file)
                
                # If you make it to the end of the while loop, you're done
                break
693000
def _release_lock(self):
        """"""
        if not self._has_lock():
            return

        # if someone removed our file beforhand, lets just flag this issue
        # instead of failing, to make it more usable.
        lfp = self._lock_file_path()
        try:
            rmfile(lfp)
        except OSError:
            pass
        self._owns_lock = False
263516
public static FileLock tryLock(FileSystem fs, Path fileToLock, Path lockDirPath, String spoutId)
          throws IOException {
    Path lockFile = new Path(lockDirPath, fileToLock.getName());

    try {
      FSDataOutputStream ostream = HdfsUtils.tryCreateFile(fs, lockFile);
      if (ostream != null) {
        LOG.debug("Acquired lock on file {}. LockFile= {}, Spout = {}", fileToLock, lockFile, spoutId);
        return new FileLock(fs, lockFile, ostream, spoutId);
      } else {
        LOG.debug("Cannot lock file {} as its already locked. Spout = {}", fileToLock, spoutId);
        return null;
      }
    } catch (IOException e) {
      LOG.error("Error when acquiring lock on file " + fileToLock + " Spout = " + spoutId, e);
      throw e;
    }
  }
1176757
def lock(&block)
      lockfile = Lockfile.new File.join(GitModel.repo.path, 'refs/heads', branch + '.lock')
      begin
        lockfile.lock
        yield
      ensure
        lockfile.unlock
      end
    end
638051
def unlock(self, password = None, keyfile = None, buf = None):
        

        if ((password is None or password == "") and (keyfile is None or
             keyfile == "")):
            raise KPError("A password/keyfile is needed")
        elif ((type(password) is not str and password is not None) or
              (type(keyfile) is not str and keyfile is not None)):
            raise KPError("password/keyfile must be a string.")
        if keyfile == "":
            keyfile = None
        if password == "":
            password = None
        self.password = password
        self.keyfile = keyfile
        return self.load(buf)
67599
def release_lock(self):
    
    if not self._lock.acquired:
      return False
    else:
      self._lock.release()
      return True
831450
def lock_file(path, maxdelay=.1, lock_cls=LockFile, timeout=10.0):
    
    lock = lock_cls(path)
    max_t = time.time() + timeout
    while True:
        if time.time() >= max_t:
            raise LockTimeout("Timeout waiting to acquire lock for %s" % (path,))  # same exception messages as in lockfile
        try:
            lock.acquire(timeout=0)
        except AlreadyLocked:
            sleep(maxdelay)
        else:
            try:
                yield lock
                break
            finally:
                lock.release()
1094003
def write_lock
      index = lock_modify_index.nil? ? 0 : lock_modify_index
      value = generate_lockfile
      return true if value == true
      Diplomat::Kv.put(@lock, value, cas: index)
    end
472833
private boolean processLockingMechanism() throws JournalException {
        boolean locked;
        if (lockRequestedFile.exists()) {
            try {
                if (!lockAcceptedFile.exists()) {
                    lockAcceptedFile.createNewFile();
                }
            } catch (IOException e) {
                throw new JournalException("Unable to create 'Lock Accepted' file at '"
                        + lockAcceptedFile.getPath() + "'");
            }
            locked = true;
        } else {
            if (lockAcceptedFile.exists()) {
                lockAcceptedFile.delete();
            }
            locked = false;
        }

        if (locked && !wasLocked) {
            recoveryLog.log("Lock request detected: "
                    + lockRequestedFile.getPath() + ", Lock accepted: "
                    + lockAcceptedFile.getPath());
        } else if (wasLocked && !locked) {
            recoveryLog.log("Lock request removed: "
                    + lockRequestedFile.getPath());
        }

        wasLocked = locked;
        return locked;
    }
219018
def synchronized(lock):
    
    def wrap(f):
        def synchronize(*args, **kw):
            lock.acquire()
            try:
                return f(*args, **kw)
            finally:
                lock.release()
        return synchronize
    return wrap
304851
public static final void useFileLocking(boolean useFileLocking)
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "useFileLocking", new Boolean(useFileLocking));

        _useFileLocking = useFileLocking;

        if (tc.isEntryEnabled())
            Tr.exit(tc, "useFileLocking");
    }