Updating locking in plugins after rebasing
This commit is contained in:
parent
dbd3a0828a
commit
f860ea10c4
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue