<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_variable(self, key, per_reference=None, access_key=None, default=None):
 """Fetches the value of a global variable :param key: the key of the global variable to be fetched :param bool per_reference: a flag to decide if the variable should be stored per reference or per value :param access_key: if the variable was explicitly locked with the rafcon.state lock_variable :param default: a value to be returned if the key does not exist :return: The value stored at in the global variable key :raises exceptions.RuntimeError: if a wrong access key is passed or the variable cannot be accessed by reference """

        key = str(key)
        if self.variable_exist(key):
            unlock = True
            if self.is_locked(key):
                if self.__access_keys[key] == access_key:
                    unlock = False
                else:
                    if not access_key:
                        access_key = self.lock_variable(key, block=True)
                    else:
                        raise RuntimeError("Wrong access key for accessing global variable")
            else:
                access_key = self.lock_variable(key, block=True)

            # --- variable locked
            if self.variable_can_be_referenced(key):
                if per_reference or per_reference is None:
                    return_value = self.__global_variable_dictionary[key]
                else:
                    return_value = copy.deepcopy(self.__global_variable_dictionary[key])
            else:
                if per_reference:
                    self.unlock_variable(key, access_key)
                    raise RuntimeError("Variable cannot be accessed by reference")
                else:
                    return_value = copy.deepcopy(self.__global_variable_dictionary[key])
            # --- release variable

            if unlock:
                self.unlock_variable(key, access_key)
            return return_value
        else:
            # logger.warning("Global variable '{0}' not existing, returning default value".format(key))
            return default