From 3a9f3c37643fe14888109cca6e3c19d15057fa10 Mon Sep 17 00:00:00 2001 From: Tadeu Manoel Date: Thu, 18 Jan 2024 18:00:12 -0300 Subject: [PATCH] Add comment and minor improvement to #581 --- conda_lock/invoke_conda.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conda_lock/invoke_conda.py b/conda_lock/invoke_conda.py index 692ac4e4..5c5a9768 100644 --- a/conda_lock/invoke_conda.py +++ b/conda_lock/invoke_conda.py @@ -116,6 +116,11 @@ def _invoke_conda( encoding="utf-8", ) as p: stdout = [] + # Using a thread so that both stdout and stderr can be consumed concurrently. + # This avoids a potential deadlock when the child conda process is trying to + # write to stderr (blocked, because the I/O is line-buffered) and conda-lock + # is still trying to read from stdout. + stdout_thread = None if p.stdout: def read_stdout() -> None: @@ -131,7 +136,7 @@ def read_stdout() -> None: for line in p.stderr: stderr.append(line) logging.error(line.rstrip()) - if p.stdout: + if stdout_thread: stdout_thread.join() if check_call and p.returncode != 0: