From 1d35cee3328488f96fb2859daae56e89383cda6f Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 1 Sep 2018 18:49:50 +0100 Subject: [PATCH] Log when a module is unloaded, including how many references are left to the module object --- ModuleManager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ModuleManager.py b/ModuleManager.py index d2457ae5..e0b5a215 100644 --- a/ModuleManager.py +++ b/ModuleManager.py @@ -91,4 +91,10 @@ class ModuleManager(object): self.events.purge_context(event_context) del sys.modules[name] + references = sys.getrefcount(module) del module + references -= 1 # 'del module' removes one reference + references -= 1 # one of the refs is from getrefcount + + self.bot.log.info("Module '%s' unloaded (%d reference%s)", + [name, references, "" if references == 1 else "s"])