From 56de4611d84abd67884d0e6c5ab4b4a561442d32 Mon Sep 17 00:00:00 2001 From: Mathieu <923463-mathbou@users.noreply.gitlab.com> Date: Sun, 17 Mar 2024 00:53:28 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix=20pipe=20reading=20hangi?= =?UTF-8?q?ng=20indefinitely?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pip_audit/_subprocess.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pip_audit/_subprocess.py b/pip_audit/_subprocess.py index 72bd20de..efe80f3c 100644 --- a/pip_audit/_subprocess.py +++ b/pip_audit/_subprocess.py @@ -36,7 +36,7 @@ def run(args: Sequence[str], *, log_stdout: bool = False, state: AuditState = Au # Run the process with unbuffered I/O, to make the poll-and-read loop below # more responsive. - process = Popen(args, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # NOTE(ww): We frequently run commands inside of ephemeral virtual environments, # which have long absolute paths on some platforms. These make for confusing @@ -52,9 +52,8 @@ def run(args: Sequence[str], *, log_stdout: bool = False, state: AuditState = Au # once `stdout` hits EOF, so we don't have to worry about that blocking. while not terminated: terminated = process.poll() is not None - # NOTE(ww): Buffer size chosen arbitrarily here and below. - stdout += process.stdout.read(4096) # type: ignore - stderr += process.stderr.read(4096) # type: ignore + stdout += process.stdout.read() # type: ignore + stderr += process.stderr.read() # type: ignore state.update_state( f"Running {pretty_args}", stdout.decode(errors="replace") if log_stdout else None, From b6f0df5bd701e9734263b6f955f856086f2ad70b Mon Sep 17 00:00:00 2001 From: Mathieu <923463-mathbou@users.noreply.gitlab.com> Date: Mon, 1 Apr 2024 17:54:22 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=8F=AA=20re-set=20bufsize=20to=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pip_audit/_subprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pip_audit/_subprocess.py b/pip_audit/_subprocess.py index efe80f3c..32b43885 100644 --- a/pip_audit/_subprocess.py +++ b/pip_audit/_subprocess.py @@ -36,7 +36,7 @@ def run(args: Sequence[str], *, log_stdout: bool = False, state: AuditState = Au # Run the process with unbuffered I/O, to make the poll-and-read loop below # more responsive. - process = Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = Popen(args, bufsize=0, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # NOTE(ww): We frequently run commands inside of ephemeral virtual environments, # which have long absolute paths on some platforms. These make for confusing