From e018b2a723f0cd8cd4c48c1c4b7fa0cfcf2122dd Mon Sep 17 00:00:00 2001 From: nico Date: Mon, 17 Aug 2015 13:33:19 +0200 Subject: [PATCH] Add plugin managers cache --- hbmqtt/plugins/manager.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hbmqtt/plugins/manager.py b/hbmqtt/plugins/manager.py index 201a323..36478a3 100644 --- a/hbmqtt/plugins/manager.py +++ b/hbmqtt/plugins/manager.py @@ -10,14 +10,20 @@ from collections import namedtuple Plugin = namedtuple('Plugin', ['name', 'ep', 'object']) +plugins_manager = dict() + +def get_plugin_manager(namespace): + global plugins_manager + return plugins_manager.get(namespace, None) class PluginManager: """ Wraps setuptools Entry point mechanism to provide a basic plugin system. Plugins are loaded for a given namespace (group). - This plugin manager uses coroutines to run plugin call asynchrounously in an event queue + This plugin manager uses coroutines to run plugin call asynchronously in an event queue """ def __init__(self, namespace, context, loop=None): + global plugins_manager if loop is not None: self._loop = loop else: @@ -27,6 +33,7 @@ class PluginManager: self.context = context self._plugins = [] self._load_plugins(namespace) + plugins_manager[namespace] = self @property def app_context(self): @@ -114,7 +121,7 @@ class PluginManager: def _get_coro(plugin, coro_name, *args, **kwargs): try: return getattr(plugin.object, coro_name, None)(*args, **kwargs) - except TypeError as te: + except TypeError: # Plugin doesn't implement coro_name return None