Acquire the lock.

        A lock can be claimed if any of these conditions are true:
            1. The lock is unheld by anyone.
            2. The lock is held but the 'force' argument is set.
            3. The lock is held by the current process.

        Arguments:
            replace_stale (bool, optional) If true, lock can be aquired from
                stale processes. A stale process is one which currently owns
                the parent lock, but no process with that PID is alive.
            force (bool, optional): If true, ignore any existing
              lock. If false, fail if lock already claimed.

        Returns:
            LockFile: self.

        Raises:
            UnableToAcquireLockError: If the lock is already claimed
              (not raised if force option is used).

def acquire(self, replace_stale=False, force=False):
        """
        Acquire the lock.

        A lock can be claimed if any of these conditions are true:
            1. The lock is unheld by anyone.
            2. The lock is held but the 'force' argument is set.
            3. The lock is held by the current process.

        Arguments:
            replace_stale (bool, optional) If true, lock can be aquired from
                stale processes. A stale process is one which currently owns
                the parent lock, but no process with that PID is alive.
            force (bool, optional): If true, ignore any existing
              lock. If false, fail if lock already claimed.

        Returns:
            LockFile: self.

        Raises:
            UnableToAcquireLockError: If the lock is already claimed
              (not raised if force option is used).
        """

        def _create_lock():
            LockFile.write(self.path, os.getpid(), time.time())

        if self.islocked:
            lock_owner_pid = self.pid

            if self.owned_by_self:
                pass  # don't replace existing lock
            elif force:
                _create_lock()
            elif replace_stale and not system.isprocess(lock_owner_pid):
                _create_lock()
            else:
                raise UnableToAcquireLockError(self)
        else:  # new lock
            _create_lock()

        return self