'Acquire this lock.
@rtype: C{bool}
@return: True if the lock is acquired, false otherwise.
@raise: Any exception os.symlink() may raise, other than
EEXIST.'

def lock(self):

    clean = True
    while True:
        try:
            symlink(str(os.getpid()), self.name)
        except OSError as e:
            if (_windows and (e.errno in (errno.EACCES, errno.EIO))):
                return False
            if (e.errno == errno.EEXIST):
                try:
                    pid = readlink(self.name)
                except OSError as e:
                    if (e.errno == errno.ENOENT):
                        continue
                    raise
                except IOError as e:
                    if (_windows and (e.errno == errno.EACCES)):
                        return False
                    raise
                try:
                    if (kill is not None):
                        kill(int(pid), 0)
                    p = psutil.Process(int(pid))
                    if (os.name == 'nt'):
                        conditions = [('spyder' in c.lower()) for c in p.cmdline()]
                    else:
                        conditions = [(p.name() == 'spyder'), (p.name() == 'spyder3')]
                    conditions += [('bootstrap.py' in p.cmdline())]
                    if (not any(conditions)):
                        raise OSError(errno.ESRCH, 'No    such    process')
                except OSError as e:
                    if (e.errno == errno.ESRCH):
                        try:
                            rmlink(self.name)
                        except OSError as e:
                            if (e.errno == errno.ENOENT):
                                continue
                            raise
                        clean = False
                        continue
                    raise
                return False
            raise
        self.locked = True
        self.clean = clean
        return True
