# Buggy code
def save_config(self):
    """
    save the environment parameters in config file
    """
    for k in SAVED_ATTR:
        try:
            setattr(self.session, "set_cm_%s" % k, getattr(self.settings, k))
        except OperationNotPossibleAtRuntimeException:
            # some of the attribute can't be changed in runtime. See lm.sessconfig_changed_callback
            self._logger.debug("Cannot set attribute %s. Not permitted in runtime", k)

    archive_sources = []
    lboosting_sources = []
    flag_enabled_sources = []
    flag_disabled_sources = []
    for boosting_source_name, boosting_source in self.boosting_sources.iteritems():
        bsname = source_to_string(boosting_source_name)

        lboosting_sources.append(bsname)
        if boosting_source.enabled:
            flag_enabled_sources.append(bsname)
        else:
            flag_disabled_sources.append(bsname)

        if boosting_source.archive:
            archive_sources.append(bsname)

    self.session.set_cm_sources(lboosting_sources, CONFIG_KEY_SOURCELIST)
    self.session.set_cm_sources(flag_enabled_sources, CONFIG_KEY_ENABLEDLIST)
    self.session.set_cm_sources(flag_disabled_sources, CONFIG_KEY_DISABLEDLIST)
    self.session.set_cm_sources(archive_sources, CONFIG_KEY_ARCHIVELIST)

    self.session.save_pstate_sessconfig()


# Traceback (AssertionError)
ERROR   1472497939.37  LaunchManyCore:637   Exception while checkpointing: tails-i386-2.3
Traceback (most recent call last):
File "/home/vi/home/tribler/tribler/Tribler/Core/APIImplementation/LaunchManyCore.py", line 634, in network_checkpoint_callback
self.save_download_pstate(infohash, pstate)
File "/home/vi/home/tribler/tribler/Tribler/Core/APIImplementation/LaunchManyCore.py", line 808, in save_download_pstate
self.downloads[infohash].save_resume_data())
File "/home/vi/home/tribler/tribler/Tribler/dispersy/taskmanager.py", line 41, in register_task
assert not self.is_pending_task_active(name), name
AssertionError: save_pstate 1862.259269

# Fixed code
def save_config(self):
    """
    save the environment parameters in config file
    """
    for k in SAVED_ATTR:
        try:
            setattr(self.session, "set_cm_%s" % k, getattr(self.settings, k))
        except OperationNotPossibleAtRuntimeException:
            # some of the attribute can't be changed in runtime. See lm.sessconfig_changed_callback
            self._logger.debug("Cannot set attribute %s. Not permitted in runtime", k)

    archive_sources = []
    lboosting_sources = []
    flag_enabled_sources = []
    flag_disabled_sources = []
    for boosting_source_name, boosting_source in self.boosting_sources.iteritems():
        bsname = source_to_string(boosting_source_name)

        lboosting_sources.append(bsname)
        if boosting_source.enabled:
            flag_enabled_sources.append(bsname)
        else:
            flag_disabled_sources.append(bsname)

        if boosting_source.archive:
            archive_sources.append(bsname)

    self.session.set_cm_sources(lboosting_sources, CONFIG_KEY_SOURCELIST)
    self.session.set_cm_sources(flag_enabled_sources, CONFIG_KEY_ENABLEDLIST)
    self.session.set_cm_sources(flag_disabled_sources, CONFIG_KEY_DISABLEDLIST)
    self.session.set_cm_sources(archive_sources, CONFIG_KEY_ARCHIVELIST)

    self.session.save_session_config()