'Acquire the lock.
Creates the PID file for this lock, or raises an error if
the lock could not be acquired.'

def acquire(self, timeout=None):

    timeout = (timeout if (timeout is not None) else self.timeout)
    end_time = time.time()
    if ((timeout is not None) and (timeout > 0)):
        end_time += timeout
    while True:
        try:
            write_pid_to_pidfile(self.path)
        except OSError as exc:
            if (exc.errno == errno.EEXIST):
                if (time.time() > end_time):
                    if ((timeout is not None) and (timeout > 0)):
                        raise LockTimeout(('Timeout    waiting    to    acquire    lock    for    %s' % self.path))
                    else:
                        raise AlreadyLocked(('%s    is    already    locked' % self.path))
                time.sleep((((timeout is not None) and (timeout / 10)) or 0.1))
            else:
                raise LockFailed(('failed    to    create    %s' % self.path))
        else:
            return
