<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lock_variable(self, key, block=False):
 """Locks a global variable :param key: the key of the global variable to be locked :param block: a flag to specify if to wait for locking the variable in blocking mode """

        key = str(key)
        # watch out for releasing the __dictionary_lock properly
        try:
            if key in self.__variable_locks:
                # acquire without arguments is blocking
                lock_successful = self.__variable_locks[key].acquire(False)
                if lock_successful or block:
                    if (not lock_successful) and block:  # case: lock could not be acquired => wait for it as block=True
                        duration = 0.
                        loop_time = 0.1
                        while not self.__variable_locks[key].acquire(False):
                            time.sleep(loop_time)
                            duration += loop_time
                            if int(duration*10) % 20 == 0:
                                # while loops informs the user about long locked variables
                                logger.verbose("Variable '{2}' is locked and thread {0} waits already {1} seconds to "
                                               "access it.".format(currentThread(), duration, key))
                    access_key = global_variable_id_generator()
                    self.__access_keys[key] = access_key
                    return access_key
                else:
                    logger.warning("Global variable {} already locked".format(str(key)))
                    return False
            else:
                logger.error("Global variable key {} does not exist".format(str(key)))
                return False
        except Exception as e:
            logger.error("Exception thrown: {}".format(str(e)))
            return False