From adafd6bd01f5c3bb1793b99e02598d44a5002d3c Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 20 Mar 2023 01:11:24 +0000 Subject: [PATCH] Fix race condition in subprocess runner stdin, stdout, and stderr being closed does not necessarily imply that the process has exited, although it usually does. Still need to explicitly wait for it to terminate after the I/O loop. This matches what the stdlib `subprocess.Popen._communicate` does as well. --- codearchiver/subprocess.py | 1 + 1 file changed, 1 insertion(+) diff --git a/codearchiver/subprocess.py b/codearchiver/subprocess.py index 5422851..5a187cd 100644 --- a/codearchiver/subprocess.py +++ b/codearchiver/subprocess.py @@ -66,6 +66,7 @@ def run_with_log(args, *, check = True, input = None, **kwargs): stdout.append(data) if stderrBuf: _logger.info(stderrBuf.decode('utf-8')) + p.wait() assert p.poll() is not None if input is not None and stdinOffset < len(input): _logger.warning(f'Could not write all input to the stdin pipe (wanted to write {len(input)} bytes, only wrote {stdinOffset})')