def acquire_lock(self, force=False):
        """
        Takes out a lock (creates a <dbname>.lock file) for the database.
        
        :param force: Whether to force taking "ownership" of the lock file.
        :type force: bool
        :raises: :class:`keepassdb.exc.DatabaseAlreadyLocked` - If the database is already locked (and force not set to True).
        """
        if self.readonly:
            raise exc.ReadOnlyDatabase()
        if not self._locked:
            self.log.debug("Acquiring lock file: {0}".format(self.lockfile))
            if os.path.exists(self.lockfile) and not force:
                raise exc.DatabaseAlreadyLocked('Lock file already exists: {0}'.format(self.lockfile)) 
            open(self.lockfile, 'w').close()
            self._locked = True