From 2f71ef4264de9b814e111236efc05b2de63e1db1 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Sun, 5 Jun 2011 22:28:37 +0100 Subject: [PATCH] Work around plugins being garbage collected once enabled twice. When a plugin is enabled, disabled and then enabled again, on that second enable, that instance is being garbage collected causing the loading of the plugin to fail. Work around that until we can narrow down why is this is happening on the second enable. --- deluge/component.py | 19 +++++++++++++++++-- deluge/pluginmanagerbase.py | 5 +++++ deluge/plugins/pluginbase.py | 6 +++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/deluge/component.py b/deluge/component.py index 9fa4e3c67..af923e66c 100644 --- a/deluge/component.py +++ b/deluge/component.py @@ -97,10 +97,11 @@ class Component(object): self._component_starting_deferred = None self._component_stopping_deferred = None _ComponentRegistry.register(self) + log.debug("Component '%s' initialized", self._component_name) def __del__(self): _ComponentRegistry.deregister(self._component_name) - + def _component_start_timer(self): if hasattr(self, "update"): self._component_timer = LoopingCall(self.update) @@ -149,7 +150,7 @@ class Component(object): self._component_stopping_deferred = None log.error(result) return result - + if self._component_state != "Stopped" and self._component_state != "Stopping": if hasattr(self, "stop"): self._component_state = "Stopping" @@ -250,6 +251,18 @@ class ComponentRegistry(object): else: return succeed(None) + def registered(self, name): + """ + Check if a component is registered with the us + + :param name: the Component name to check + :type name: string + + :returns: True or False + :rtype: bolean + """ + return name in self.components + def start(self, names=[]): """ Starts Components that are currently in a Stopped state and their @@ -392,7 +405,9 @@ class ComponentRegistry(object): _ComponentRegistry = ComponentRegistry() +register = _ComponentRegistry.register deregister = _ComponentRegistry.deregister +registered = _ComponentRegistry.registered start = _ComponentRegistry.start stop = _ComponentRegistry.stop pause = _ComponentRegistry.pause diff --git a/deluge/pluginmanagerbase.py b/deluge/pluginmanagerbase.py index e2eb84e90..4a723556c 100644 --- a/deluge/pluginmanagerbase.py +++ b/deluge/pluginmanagerbase.py @@ -166,8 +166,13 @@ class PluginManagerBase: DeprecationWarning, instance.__module__, 0 ) + + if not component.registered(instance.plugin._component_name): + component.register(instance.plugin) + if self._component_state == "Started": component.start([instance.plugin._component_name]) + plugin_name = plugin_name.replace("-", " ") self.plugins[plugin_name] = instance if plugin_name not in self.config["enabled_plugins"]: diff --git a/deluge/plugins/pluginbase.py b/deluge/plugins/pluginbase.py index a59aab754..55c48de7e 100644 --- a/deluge/plugins/pluginbase.py +++ b/deluge/plugins/pluginbase.py @@ -56,12 +56,12 @@ class CorePluginBase(PluginBase): super(CorePluginBase, self).__init__("CorePlugin." + plugin_name) # Register RPC methods component.get("RPCServer").register_object(self, plugin_name.lower()) - log.debug("CorePlugin initialized..") + log.debug("CorePlugin '%s' initialized..", plugin_name) class GtkPluginBase(PluginBase): def __init__(self, plugin_name): super(GtkPluginBase, self).__init__("GtkPlugin." + plugin_name) - log.debug("GtkPlugin initialized..") + log.debug("GtkPlugin '%s' initialized..", plugin_name) class WebPluginBase(PluginBase): @@ -76,7 +76,7 @@ class WebPluginBase(PluginBase): # Register JSON rpc methods component.get("JSON").register_object(self, plugin_name.lower()) - log.debug("WebPlugin initialized..") + log.debug("WebPlugin '%s' initialized..", plugin_name) def enable(self): pass