1# (c) 2016 - Red Hat, Inc. <info@ansible.com> 2# 3# This file is part of Ansible 4# 5# Ansible is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# Ansible is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with Ansible. If not, see <http://www.gnu.org/licenses/>. 17 18# Make coding more python3-ish 19from __future__ import (absolute_import, division, print_function) 20__metaclass__ = type 21 22from multiprocessing import Lock 23 24from ansible.module_utils.facts.system.pkg_mgr import PKG_MGRS 25 26if 'action_write_locks' not in globals(): 27 # Do not initialize this more than once because it seems to bash 28 # the existing one. multiprocessing must be reloading the module 29 # when it forks? 30 action_write_locks = dict() 31 32 # Below is a Lock for use when we weren't expecting a named module. It gets used when an action 33 # plugin invokes a module whose name does not match with the action's name. Slightly less 34 # efficient as all processes with unexpected module names will wait on this lock 35 action_write_locks[None] = Lock() 36 37 # These plugins are known to be called directly by action plugins with names differing from the 38 # action plugin name. We precreate them here as an optimization. 39 # If a list of service managers is created in the future we can do the same for them. 40 mods = set(p['name'] for p in PKG_MGRS) 41 42 mods.update(('copy', 'file', 'setup', 'slurp', 'stat')) 43 for mod_name in mods: 44 action_write_locks[mod_name] = Lock() 45