From 9b8282010c69790fea04ba2fc733ea0f60203746 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 8 Nov 2009 04:04:40 +0000 Subject: [PATCH] Fix disabling/enabling plugins after switching daemons --- deluge/component.py | 21 +++++++++++++++++++-- deluge/pluginmanagerbase.py | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/deluge/component.py b/deluge/component.py index 764c38609..f433ad6e0 100644 --- a/deluge/component.py +++ b/deluge/component.py @@ -101,6 +101,13 @@ class ComponentRegistry: if depend != None: self.depend[name] = depend + def deregister(self, name): + """Deregisters a component""" + if name in self.components: + log.debug("Deregistering Component: %s", name) + self.stop_component(name) + del self.components[name] + def get(self, name): """Returns a reference to the component 'name'""" return self.components[name] @@ -126,8 +133,14 @@ class ComponentRegistry: def stop(self): """Stops all components""" - for component in self.components.keys(): - self.stop_component(component) + # We create a separate list of the keys and do an additional check to + # make sure the key still exists in the components dict. + # This is because components could be deregistered during a stop and + # the dictionary would get modified while iterating through it. + components = self.components.keys() + for component in components: + if component in self.components: + self.stop_component(component) def stop_component(self, component): if self.components[component].get_state() != \ @@ -187,6 +200,10 @@ def register(name, obj, depend=None): """Registers a component with the registry""" _ComponentRegistry.register(name, obj, depend) +def deregister(name): + """Deregisters a component""" + _ComponentRegistry.deregister(name) + def start(component=None): """Starts all components""" if component == None: diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index 7a899475e..35c551d25 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -87,7 +87,7 @@ class PluginManagerBase: def disable_plugins(self): # Disable all plugins that are enabled for key in self.plugins.keys(): - self.plugins[key].disable() + self.disable_plugin(key) def __getitem__(self, key): return self.plugins[key] @@ -153,6 +153,7 @@ class PluginManagerBase: """Disables a plugin""" try: self.plugins[name].disable() + component.deregister(self.plugins[name].plugin.get_component_name()) del self.plugins[name] self.config["enabled_plugins"].remove(name) except KeyError: