add lock in module.__init()__
@@ -120,12 +120,13 @@ class Module(object):
self.cache_program = None
fp_lock = open(os.path.join(CONF_HOME, 'config.json'))
- if name:
lock.flock(fp_lock, lock.LOCK_EX)
+ if name:
self._init_with_name(name=name, version=version)
lock.flock(fp_lock, lock.LOCK_UN)
elif module_dir:
self._init_with_module_file(module_dir=module_dir[0])
+ lock.flock(fp_lock, lock.LOCK_UN)
elif signatures:
if processor:
if not issubclass(processor, BaseProcessor):
@@ -139,11 +140,12 @@ class Module(object):
self.processor = processor
self._generate_module_info(module_info)
self._init_with_signature(signatures=signatures)
+ lock.flock(fp_lock, lock.LOCK_UN)
else:
+ lock.flock(fp_lock, lock.LOCK_UN)
raise ValueError("Module initialized parameter is empty")
def _init_with_name(self, name, version=None):
- lock.write_acquire()
log_msg = "Installing %s module" % name
if version:
log_msg += "-%s" % version
@@ -154,7 +156,6 @@ class Module(object):
logger.error(tips)
exit(1)
logger.info(tips)
- lock.write_release()
self._init_with_module_file(module_dir[0])
def _init_with_url(self, url):
@@ -206,7 +207,6 @@ class Module(object):
self.assets.append(filepath)
def _init_with_module_file(self, module_dir):
- lock.write_acquire()
checker = ModuleChecker(module_dir)
checker.check()
@@ -228,7 +228,6 @@ class Module(object):
self._generate_extra_info()
self._restore_parameter(self.program)
self._recover_variable_info(self.program)
- lock.write_release()
def _init_with_signature(self, signatures):
self.name_prefix = HUB_VAR_PREFIX % self.name
