diff options
author | James Cammarata <jimi@sngx.net> | 2017-09-22 10:49:42 -0500 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2017-10-02 12:25:00 -0500 |
commit | f860ea10c4e4c65a8529f3b49ecca1ee22e1b482 (patch) | |
tree | 6cef0b0ed793a95b9b6032afe82da19848814f2b | |
parent | dbd3a0828a676163a1a80923b523c7f231a5da90 (diff) | |
download | ansible-f860ea10c4e4c65a8529f3b49ecca1ee22e1b482.tar.gz |
Updating locking in plugins after rebasing
-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, |