fe735e35c6
Why I did it This PR is part of sonic-mgmt-docker Python3 migration project. Work item tracking Microsoft ADO (number only): 24397943 How I did it Upgrade Ansible to 6.7.0 Make Python3 as the default interpreter. python is a soft link to python3. If you want to use python2, use the command python2 explicitly. Upgrade some pip packages to higher version in order to meet security requirement. How to verify it Build a private sonic-mgmt-docker successfully. Verify python is python3. Verify python2 is working with 202012 and 202205 branch. Verify python3 is working with master branch. Verify with github PR test.
47 lines
2.0 KiB
Diff
47 lines
2.0 KiB
Diff
From e323263795a0af4c9c61992bd7a3347d8928db39 Mon Sep 17 00:00:00 2001
|
|
From: Xin Wang <xiwang5@microsoft.com>
|
|
Date: Thu, 14 Sep 2023 16:52:54 +0800
|
|
Subject: [PATCH] Fix getattr AttributeError in multi-thread scenario
|
|
|
|
When multi-thread is used, the plugin loader may raise AttributeError
|
|
while getting "ActionModule" from an action plugin.
|
|
|
|
The reason is that cache is used while loading module. Before a module
|
|
is fully loaded, it is already put into the sys.modules cache. When another
|
|
thread tries to load the same module, it would load an incompletely loaded
|
|
module from the sys.modules cache. Then while getting "ActionModule"
|
|
attribute from this module, exception AttributeError could be raised.
|
|
|
|
Signed-off-by: Xin Wang <xiwang5@microsoft.com>
|
|
---
|
|
lib/ansible/plugins/loader.py | 11 +++++------
|
|
1 file changed, 5 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/lib/ansible/plugins/loader.py b/lib/ansible/plugins/loader.py
|
|
index 74bdeb5719..251531b62e 100644
|
|
--- a/lib/ansible/plugins/loader.py
|
|
+++ b/lib/ansible/plugins/loader.py
|
|
@@ -801,15 +801,14 @@ class PluginLoader:
|
|
warnings.simplefilter("ignore", RuntimeWarning)
|
|
spec = importlib.util.spec_from_file_location(to_native(full_name), to_native(path))
|
|
module = importlib.util.module_from_spec(spec)
|
|
-
|
|
- # mimic import machinery; make the module-being-loaded available in sys.modules during import
|
|
- # and remove if there's a failure...
|
|
- sys.modules[full_name] = module
|
|
-
|
|
try:
|
|
spec.loader.exec_module(module)
|
|
+ # mimic import machinery; make the module-being-loaded available in sys.modules during import
|
|
+ # and remove if there's a failure...
|
|
+ sys.modules[full_name] = module
|
|
except Exception:
|
|
- del sys.modules[full_name]
|
|
+ if full_name in sys.modules:
|
|
+ del sys.modules[full_name]
|
|
raise
|
|
|
|
return module
|
|
--
|
|
2.25.1
|