diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2016-02-11 22:10:01 -0500 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2016-02-11 22:19:41 -0500 |
commit | 4a043d5e8289d4deb2d9a8e96b2291b54934512f (patch) | |
tree | 1128df4ec94283500d26237d9d816573ef0dd873 | |
parent | d99955596e32901e0230bb549a285ec04a6dbdcc (diff) | |
download | ansible-4a043d5e8289d4deb2d9a8e96b2291b54934512f.tar.gz |
switched threading to multiprocessing
both really work the same for the Lock but this hopefully will
avoid confusing people into thinking we are threaded or thread safe
Also did pyflakes cleanup and made note why checksums import exists
-rw-r--r-- | lib/ansible/cache/memcached.py | 4 | ||||
-rw-r--r-- | lib/ansible/runner/connection_plugins/accelerate.py | 7 | ||||
-rw-r--r-- | lib/ansible/utils/__init__.py | 15 |
3 files changed, 8 insertions, 18 deletions
diff --git a/lib/ansible/cache/memcached.py b/lib/ansible/cache/memcached.py index ea922434b5..470ab6b224 100644 --- a/lib/ansible/cache/memcached.py +++ b/lib/ansible/cache/memcached.py @@ -19,8 +19,8 @@ import collections import os import sys import time -import threading from itertools import chain +from multiprocessing import Lock from ansible import constants as C from ansible.cache.base import BaseCacheModule @@ -51,7 +51,7 @@ class ProxyClientPool(object): self._num_connections = 0 self._available_connections = collections.deque(maxlen=self.max_connections) self._locked_connections = set() - self._lock = threading.Lock() + self._lock = Lock() def _check_safe(self): if self.pid != os.getpid(): diff --git a/lib/ansible/runner/connection_plugins/accelerate.py b/lib/ansible/runner/connection_plugins/accelerate.py index 8b3d961854..c9a6c43570 100644 --- a/lib/ansible/runner/connection_plugins/accelerate.py +++ b/lib/ansible/runner/connection_plugins/accelerate.py @@ -15,13 +15,12 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. -import json import os import base64 import socket import struct import time -import threading +from multiprocessing import Lock from ansible.callbacks import vvv, vvvv from ansible.errors import AnsibleError, AnsibleFileNotFound from ansible.runner.connection_plugins.ssh import Connection as SSHConnection @@ -36,7 +35,7 @@ from ansible import constants # multiple of the value to speed up file reads. CHUNK_SIZE=1044*20 -_LOCK = threading.Lock() +_LOCK = Lock() class Connection(object): ''' raw socket accelerated connection ''' @@ -243,7 +242,7 @@ class Connection(object): ''' run a command on the remote host ''' if sudoable and self.runner.become and self.runner.become_method not in self.become_methods_supported: - raise errors.AnsibleError("Internal Error: this module does not support running commands via %s" % self.runner.become_method) + raise AnsibleError("Internal Error: this module does not support running commands via %s" % self.runner.become_method) if in_data: raise AnsibleError("Internal Error: this module does not support optimized module pipelining") diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 8c699d632b..5670840a56 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -19,9 +19,7 @@ import errno import sys import re import os -import shlex import yaml -import copy import optparse import operator from ansible import errors @@ -29,8 +27,7 @@ from ansible import __version__ from ansible.utils.display_functions import * from ansible.utils.plugins import * from ansible.utils.su_prompts import * -from ansible.utils.hashing import secure_hash, secure_hash_s, checksum, checksum_s, md5, md5s -from ansible.callbacks import display +from ansible.utils.hashing import secure_hash, secure_hash_s, checksum, checksum_s, md5, md5s #unused here but 'reexported' from ansible.module_utils.splitter import split_args, unquote from ansible.module_utils.basic import heuristic_log_sanitize from ansible.utils.unicode import to_bytes, to_unicode @@ -45,12 +42,11 @@ import pipes import random import difflib import warnings -import traceback import getpass import subprocess import contextlib -import threading import tempfile +from multiprocessing import Lock from vault import VaultLib @@ -64,7 +60,7 @@ LOOKUP_REGEX = re.compile(r'lookup\s*\(') PRINT_CODE_REGEX = re.compile(r'(?:{[{%]|[%}]})') CODE_REGEX = re.compile(r'(?:{%|%})') -_LOCK = threading.Lock() +_LOCK = Lock() try: # simplejson can be much faster if it's available @@ -357,9 +353,6 @@ def path_dwim_relative(original, dirname, source, playbook_base, check=True): ''' find one file in a directory one level up in a dir named dirname relative to current ''' # (used by roles code) - from ansible.utils import template - - basedir = os.path.dirname(original) if os.path.islink(basedir): basedir = unfrackpath(basedir) @@ -552,8 +545,6 @@ def _clean_data_struct(orig_data, from_remote=False, from_inventory=False): def parse_json(raw_data, from_remote=False, from_inventory=False, no_exceptions=False): ''' this version for module return data only ''' - orig_data = raw_data - # ignore stuff like tcgetattr spewage or other warnings data = filter_leading_non_json_lines(raw_data) |