def acquire(self):
        '''Acquire a lock, returning self if successful, False otherwise'''
        if self.islocked():
            if self.debug:
                lock = self._readlock()
                print 'Previous lock detected: %s' % self.pddr(lock)
            return False
        try:
            fh = open(self.path, 'w')
            fh.write(self.addr())
            fh.close()
            if self.debug:
                print 'Acquired lock: %s' % self.fddr()
        except:
            if os.path.isfile(self.path):
                try:
                    os.unlink(self.path)
                except:
                    pass
            raise (self.FileLockAcquisitionError,
                   'Error acquiring lock: %s' % self.fddr())
        return self
Acquire a lock, returning self if successful, False otherwise
recipes/Python/498171_Simple_lockfile_detect_previous_instances/recipe-498171.py