# Buggy code
def _handle_decoded_payload(self, data):
    """
    Override this method if you wish to handle the decoded data
    differently.
    """
    if "user" in data:
        log.info(
            "User {0[user]} Executing command {0[fun]} with jid {0[jid]}".format(data)
        )
    else:
        log.info("Executing command {0[fun]} with jid {0[jid]}".format(data))
    log.debug("Command details {0}".format(data))

    if isinstance(data["fun"], six.string_types):
        if data["fun"] == "sys.reload_modules":
            self.functions, self.returners, self.function_errors, self.executors = (
                self._load_modules()
            )
            self.schedule.functions = self.functions
            self.schedule.returners = self.returners
    if isinstance(data["fun"], tuple) or isinstance(data["fun"], list):
        target = Minion._thread_multi_return
    else:
        target = Minion._thread_return
    # We stash an instance references to allow for the socket
    # communication in Windows. You can't pickle functions, and thus
    # python needs to be able to reconstruct the reference on the other
    # side.
    instance = self
    if self.opts["multiprocessing"]:
        if sys.platform.startswith("win"):
            # let python reconstruct the minion on the other side if we're
            # running on windows
            instance = None
        process = multiprocessing.Process(
            target=target, args=(instance, self.opts, data)
        )
    else:
        process = threading.Thread(
            target=target, args=(instance, self.opts, data), name=data["jid"]
        )
    process.start()
    if not sys.platform.startswith("win"):
        process.join()
    else:
        self.win_proc.append(process)


# Traceback (RuntimeError)
2015-05-05 15:52:48,917 [salt.loader                                ][ERROR   ][25815] Failed to read the virtual function for states: xmpp
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1098, in process_virtual
virtual = mod.__virtual__()
File "/usr/lib/python2.6/site-packages/salt/states/xmpp.py", line 25, in __virtual__
return 'xmpp' if 'xmpp.send_msg' in __salt__ else False
File "/usr/lib64/python2.6/_abcoll.py", line 342, in __contains__
self[key]
File "/usr/lib/python2.6/site-packages/salt/utils/lazy.py", line 85, in __getitem__
if self._load(key):
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1024, in _load
ret = _inner_load(mod_name)
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 1013, in _inner_load
if self._load_module(name) and key in self._dict:
File "/usr/lib/python2.6/site-packages/salt/loader.py", line 990, in _load_module
Depends.enforce_dependencies(self._dict, self.tag)
File "/usr/lib/python2.6/site-packages/salt/utils/decorators/__init__.py", line 81, in enforce_dependencies
for module, func, fallback_function in dependent_set:
RuntimeError: Set changed size during iteration

# Fixed code
def _handle_decoded_payload(self, data):
    """
    Override this method if you wish to handle the decoded data
    differently.
    """
    if "user" in data:
        log.info(
            "User {0[user]} Executing command {0[fun]} with jid {0[jid]}".format(data)
        )
    else:
        log.info("Executing command {0[fun]} with jid {0[jid]}".format(data))
    log.debug("Command details {0}".format(data))

    if isinstance(data["fun"], six.string_types):
        if data["fun"] == "sys.reload_modules":
            self.functions, self.returners, self.function_errors, self.executors = (
                self._load_modules()
            )
            self.schedule.functions = self.functions
            self.schedule.returners = self.returners
    # We stash an instance references to allow for the socket
    # communication in Windows. You can't pickle functions, and thus
    # python needs to be able to reconstruct the reference on the other
    # side.
    instance = self
    if self.opts["multiprocessing"]:
        if sys.platform.startswith("win"):
            # let python reconstruct the minion on the other side if we're
            # running on windows
            instance = None
        process = multiprocessing.Process(
            target=self._target, args=(instance, self.opts, data)
        )
    else:
        process = threading.Thread(
            target=self._target, args=(instance, self.opts, data), name=data["jid"]
        )
    process.start()
    # TODO: remove the windows specific check?
    if not sys.platform.startswith("win") and self.opts["multiprocessing"]:
        # we only want to join() immediately if we are daemonizing a process
        process.join()
    else:
        self.win_proc.append(process)