From 96f94c0fef18cf25f772a2b241b9c4ce9ab9b74e Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 6 Apr 2021 18:26:52 +0200 Subject: [PATCH] Use a file-like obj for stdout/stderr for deadlock workaround (#74156) Fixes #74149 --- .../fragments/fix-for-workerprocess-stdout-deadlock-fix.yml | 2 ++ lib/ansible/executor/process/worker.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix-for-workerprocess-stdout-deadlock-fix.yml diff --git a/changelogs/fragments/fix-for-workerprocess-stdout-deadlock-fix.yml b/changelogs/fragments/fix-for-workerprocess-stdout-deadlock-fix.yml new file mode 100644 index 00000000000..9d8d11dcebb --- /dev/null +++ b/changelogs/fragments/fix-for-workerprocess-stdout-deadlock-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - "WorkerProcess - Python 3.5 fix for workaround for stdout deadlock in multiprocessing shutdown to avoid process hangs. (https://github.com/ansible/ansible/issues/74149)" diff --git a/lib/ansible/executor/process/worker.py b/lib/ansible/executor/process/worker.py index 983df45bca2..510928c0edc 100644 --- a/lib/ansible/executor/process/worker.py +++ b/lib/ansible/executor/process/worker.py @@ -145,8 +145,7 @@ class WorkerProcess(multiprocessing_context.Process): # 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 = os.devnull - sys.stderr = os.devnull + sys.stdout = sys.stderr = open(os.devnull, 'w') def _run(self): '''