def lock(self):
        """
        Trys to write a lock file. Returns True if we get the lock, else return
        False.
        """
        try:
            if not os.path.exists(os.path.dirname(self.LOCK_FILE)):
                os.makedirs(os.path.dirname(self.LOCK_FILE))
            self.log("Attempting acquire mutext "
                     "({0})...".format(self.LOCK_FILE))
            self.lock_fd = open(self.LOCK_FILE, 'w+')
            fcntl.flock(self.lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            self.log(self.format_title("Mutex Acquired"))
            return True
        except __HOLE__, exc_value:
            self.lock_fd = None
            #  IOError: [Errno 11] Resource temporarily unavailable
            if exc_value[0] == 11:
                self.log(
                    "DNS build script attempted to acquire the "
                    "build mutux but another process already has it."
                )
                fail_mail(
                    "An attempt was made to start the DNS build script "
                    "while an instance of the script was already running. "
                    "The attempt was denied.",
                    subject="Concurrent DNS builds attempted.")
                return False
            else:
                raise
dataset/ETHPy150Open mozilla/inventory/mozdns/mozbind/builder.py/DNSBuilder.lock