From a0b39043c07f41cfdcd2835a5ae2703ec18ec1e2 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 24 Sep 2018 16:20:58 +0100 Subject: [PATCH] Use 'bitbot_%s' import name format when unloading a module --- src/ModuleManager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ModuleManager.py b/src/ModuleManager.py index 3dc847e9..24b5fb8c 100644 --- a/src/ModuleManager.py +++ b/src/ModuleManager.py @@ -38,6 +38,8 @@ class ModuleManager(object): return os.path.basename(path).rsplit(".py", 1)[0].lower() def _module_path(self, name): return os.path.join(self.directory, "%s.py" % name) + def _import_name(self, name): + return "bitbot_%s" % name def _load_module(self, name): path = self._module_path(name) @@ -68,7 +70,7 @@ class ModuleManager(object): "waiting for requirement") else: break - module = imp.load_source("bitbot_%s" % name, path) + module = imp.load_source(self._import_name(name), path) if not hasattr(module, "Module"): raise ModuleLoadException("module '%s' doesn't have a " @@ -137,7 +139,7 @@ class ModuleManager(object): self.events.purge_context(context) self.exports.purge_context(context) - del sys.modules[name] + del sys.modules[self._import_name(name)] references = sys.getrefcount(module) del module references -= 1 # 'del module' removes one reference