From 6f445ca6e5c9c8b85ccc5062e00508c69ca26fde Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 8 Mar 2022 15:49:43 -0800 Subject: [PATCH] Remove obsolete Python 2.x controller code. --- lib/ansible/executor/process/worker.py | 6 ++---- lib/ansible/executor/task_queue_manager.py | 16 ---------------- lib/ansible/plugins/callback/__init__.py | 7 ------- lib/ansible/utils/display.py | 21 +++++++++------------ 4 files changed, 11 insertions(+), 39 deletions(-) diff --git a/lib/ansible/executor/process/worker.py b/lib/ansible/executor/process/worker.py index ee4164aa57f..4e70a342ed1 100644 --- a/lib/ansible/executor/process/worker.py +++ b/lib/ansible/executor/process/worker.py @@ -130,12 +130,10 @@ class WorkerProcess(multiprocessing_context.Process): # type: ignore[name-defin # shutdown. We have various ``Display`` calls that may fire from a fork # so we cannot do this early. Instead, this happens at the very end # to avoid that deadlock, by simply side stepping it. This should not be - # treated as a long term fix. Additionally this behavior only presents itself - # on Python3. Python2 does not exhibit the deadlock behavior. + # treated as a long term fix. # TODO: Evaluate overhauling ``Display`` to not write directly to stdout # and evaluate migrating away from the ``fork`` multiprocessing start method. - if sys.version_info[0] >= 3: - sys.stdout = sys.stderr = open(os.devnull, 'w') + sys.stdout = sys.stderr = open(os.devnull, 'w') def _run(self): ''' diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py index bc701e50627..8725a380598 100644 --- a/lib/ansible/executor/task_queue_manager.py +++ b/lib/ansible/executor/task_queue_manager.py @@ -338,22 +338,6 @@ class TaskQueueManager: self._final_q.close() self._cleanup_processes() - # A bug exists in Python 2.6 that causes an exception to be raised during - # interpreter shutdown. This is only an issue in our CI testing but we - # hit it frequently enough to add a small sleep to avoid the issue. - # This can be removed once we have split controller available in CI. - # - # Further information: - # Issue: https://bugs.python.org/issue4106 - # Fix: https://hg.python.org/cpython/rev/d316315a8781 - # - try: - if (2, 6) == (sys.version_info[0:2]): - time.sleep(0.0001) - except (IndexError, AttributeError): - # In case there is an issue getting the version info, don't raise an Exception - pass - def _cleanup_processes(self): if hasattr(self, '_workers'): for attempts_remaining in range(C.WORKER_SHUTDOWN_POLL_COUNT - 1, -1, -1): diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index c3ca6b5dcfe..0620f493725 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -384,13 +384,6 @@ class CallbackBase(AnsiblePlugin): tofiledate=u'', n=C.DIFF_CONTEXT) difflines = list(differ) - if len(difflines) >= 3 and sys.version_info[:2] == (2, 6): - # difflib in Python 2.6 adds trailing spaces after - # filenames in the -- before/++ after headers. - difflines[0] = difflines[0].replace(u' \n', u'\n') - difflines[1] = difflines[1].replace(u' \n', u'\n') - # it also treats empty files differently - difflines[2] = difflines[2].replace(u'-1,0', u'-0,0').replace(u'+1,0', u'+0,0') has_diff = False for line in difflines: has_diff = True diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index a1a45b2def8..b9d246543dc 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -264,11 +264,10 @@ class Display(metaclass=Singleton): msg2 = msg2 + u'\n' msg2 = to_bytes(msg2, encoding=self._output_encoding(stderr=stderr)) - if sys.version_info >= (3,): - # Convert back to text string on python3 - # We first convert to a byte string so that we get rid of - # characters that are invalid in the user's locale - msg2 = to_text(msg2, self._output_encoding(stderr=stderr), errors='replace') + # Convert back to text string + # We first convert to a byte string so that we get rid of + # characters that are invalid in the user's locale + msg2 = to_text(msg2, self._output_encoding(stderr=stderr), errors='replace') # Note: After Display() class is refactored need to update the log capture # code in 'bin/ansible-connection' (and other relevant places). @@ -292,9 +291,8 @@ class Display(metaclass=Singleton): # color and characters that are invalid in the user's locale msg2 = to_bytes(nocolor.lstrip(u'\n')) - if sys.version_info >= (3,): - # Convert back to text string on python3 - msg2 = to_text(msg2, self._output_encoding(stderr=stderr)) + # Convert back to text string + msg2 = to_text(msg2, self._output_encoding(stderr=stderr)) lvl = logging.INFO if color: @@ -463,10 +461,9 @@ class Display(metaclass=Singleton): @staticmethod def prompt(msg, private=False): prompt_string = to_bytes(msg, encoding=Display._output_encoding()) - if sys.version_info >= (3,): - # Convert back into text on python3. We do this double conversion - # to get rid of characters that are illegal in the user's locale - prompt_string = to_text(prompt_string) + # Convert back into text. We do this double conversion + # to get rid of characters that are illegal in the user's locale + prompt_string = to_text(prompt_string) if private: return getpass.getpass(prompt_string)