def rreload(module, mdict=None): """Recursively reload modules.""" name = module.__name__ if mdict is None: mdict = [] for attribute_name in getattr(module, '__all__', []) or []: attribute = getattr(module, attribute_name, None) if isinstance(attribute, types.ModuleType) and attribute not in mdict: mdict.append(attribute) rreload(attribute, mdict) try: _reload(module) except Exception as e: pass