def flushUnder(dirpath):
"""Flushes all modules that live under the given directory
:param dirpath: the name of the top most directory to search under.
:type dirpath: str
"""
modulePaths = list()
for name, module in sys.modules.items():
if module is None:
del sys.modules[name]
continue
try:
moduleDirpath = os.path.realpath(os.path.dirname(inspect.getfile(module)))
if moduleDirpath.startswith(dirpath):
modulePaths.append((name, inspect.getfile(sys.modules[name])))
del sys.modules[name]
logger.debug('unloaded module: %s ' % name)
except TypeError:
continue
# Force a garbage collection
gc.collect()
return modulePaths
评论列表
文章目录