提交 6dc03dc3 编写于 作者: W wuzewu

Avoid module being initialized multiple times

上级 97d92993
......@@ -120,9 +120,10 @@ def runable(func):
class Module(object):
def __new__(cls, name=None, directory=None, module_dir=None, version=None):
module = None
_record = {}
def __new__(cls, name=None, directory=None, module_dir=None, version=None):
if cls.__name__ == "Module":
if name:
module = cls.init_with_name(name=name, version=version)
......@@ -139,17 +140,18 @@ class Module(object):
else:
directory = module_dir
module = cls.init_with_directory(directory=directory)
if not module:
module = object.__new__(cls)
else:
CacheUpdater(module.name, module.version).start()
else:
module = object.__new__(cls)
return module
def __init__(self, name=None, directory=None, module_dir=None,
version=None):
if not directory:
# Avoid module being initialized multiple times
if not directory or id(self) in Module._record:
return
Module._record[id(self)] = True
mod = self.__class__.__module__ + "." + self.__class__.__name__
if mod in _module_runable_func:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册