diff options
Diffstat (limited to 'lib/ansible/plugins/loader.py')
-rw-r--r-- | lib/ansible/plugins/loader.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/ansible/plugins/loader.py b/lib/ansible/plugins/loader.py index 1e1dc84a6c..0ca284bd64 100644 --- a/lib/ansible/plugins/loader.py +++ b/lib/ansible/plugins/loader.py @@ -15,6 +15,7 @@ import sys import warnings from collections import defaultdict +from threading import Lock from ansible import constants as C from ansible.plugins import get_plugin_class, MODULE_CACHE, PATH_CACHE, PLUGIN_PATH_CACHE @@ -73,6 +74,7 @@ class PluginLoader: self._extra_dirs = [] self._searched_paths = set() + self._lock = Lock() def __setstate__(self, data): ''' @@ -360,11 +362,14 @@ class PluginLoader: if path is None: return None + self._lock.acquire() if path not in self._module_cache: self._module_cache[path] = self._load_module_source(name, path) found_in_cache = False obj = getattr(self._module_cache[path], self.class_name) + self._lock.release() + if self.base_class: # The import path is hardcoded and should be the right place, # so we are not expecting an ImportError. @@ -423,15 +428,18 @@ class PluginLoader: yield path continue - if path not in self._module_cache: - self._module_cache[path] = self._load_module_source(name, path) - found_in_cache = False - try: + self._lock.acquire() + if path not in self._module_cache: + self._module_cache[path] = self._load_module_source(name, path) + found_in_cache = False + obj = getattr(self._module_cache[path], self.class_name) except AttributeError as e: display.warning("Skipping plugin (%s) as it seems to be invalid: %s" % (path, to_text(e))) continue + finally: + self._lock.release() if self.base_class: # The import path is hardcoded and should be the right place, |