summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2024-12-10 16:38:57 +0100
committerGitHub <noreply@github.com>2024-12-10 16:38:57 +0100
commit73d8f4ad46c22e180fa3e3e1c6db1665378f674b (patch)
tree547f2a166c393972c7c7154b42095734a28cbfa5
parentFix a debug message error (#84426) (diff)
downloadansible-73d8f4ad46c22e180fa3e3e1c6db1665378f674b.tar.xz
ansible-73d8f4ad46c22e180fa3e3e1c6db1665378f674b.zip
Make sure we are always using Lock from our multiprocessing context (#84453)
* Make sure we are always using Lock from our multiprocessing context * add clog frag
-rw-r--r--changelogs/fragments/macos-correct-lock.yml2
-rw-r--r--lib/ansible/executor/action_write_locks.py6
-rw-r--r--lib/ansible/plugins/strategy/__init__.py5
3 files changed, 8 insertions, 5 deletions
diff --git a/changelogs/fragments/macos-correct-lock.yml b/changelogs/fragments/macos-correct-lock.yml
new file mode 100644
index 0000000000..d764a8eb0b
--- /dev/null
+++ b/changelogs/fragments/macos-correct-lock.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- Use consistent multiprocessing context for action write locks
diff --git a/lib/ansible/executor/action_write_locks.py b/lib/ansible/executor/action_write_locks.py
index d2acae9b6f..2934615c50 100644
--- a/lib/ansible/executor/action_write_locks.py
+++ b/lib/ansible/executor/action_write_locks.py
@@ -19,7 +19,7 @@ from __future__ import annotations
import multiprocessing.synchronize
-from multiprocessing import Lock
+from ansible.utils.multiprocessing import context as multiprocessing_context
from ansible.module_utils.facts.system.pkg_mgr import PKG_MGRS
@@ -32,7 +32,7 @@ if 'action_write_locks' not in globals():
# Below is a Lock for use when we weren't expecting a named module. It gets used when an action
# plugin invokes a module whose name does not match with the action's name. Slightly less
# efficient as all processes with unexpected module names will wait on this lock
- action_write_locks[None] = Lock()
+ action_write_locks[None] = multiprocessing_context.Lock()
# These plugins are known to be called directly by action plugins with names differing from the
# action plugin name. We precreate them here as an optimization.
@@ -41,4 +41,4 @@ if 'action_write_locks' not in globals():
mods.update(('copy', 'file', 'setup', 'slurp', 'stat'))
for mod_name in mods:
- action_write_locks[mod_name] = Lock()
+ action_write_locks[mod_name] = multiprocessing_context.Lock()
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index c9fdfeeb22..54721ad874 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -28,7 +28,7 @@ import time
import typing as t
from collections import deque
-from multiprocessing import Lock
+
from jinja2.exceptions import UndefinedError
@@ -55,6 +55,7 @@ from ansible.utils.display import Display
from ansible.utils.fqcn import add_internal_fqcns
from ansible.utils.unsafe_proxy import wrap_var
from ansible.utils.vars import combine_vars
+from ansible.utils.multiprocessing import context as multiprocessing_context
from ansible.vars.clean import strip_internal_keys, module_response_deepcopy
display = Display()
@@ -365,7 +366,7 @@ class StrategyBase:
if task.action not in action_write_locks.action_write_locks:
display.debug('Creating lock for %s' % task.action)
- action_write_locks.action_write_locks[task.action] = Lock()
+ action_write_locks.action_write_locks[task.action] = multiprocessing_context.Lock()
# create a templar and template things we need later for the queuing process
templar = Templar(loader=self._loader, variables=task_vars)