From b16b79b9df46a948f66b8d9bc4c745885acbb164 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Wed, 12 Feb 2025 18:09:35 -0800 Subject: [PATCH] Playing with exposing the subprocess while inside run --- src/rocker/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rocker/core.py b/src/rocker/core.py index 0117613..c28bd73 100644 --- a/src/rocker/core.py +++ b/src/rocker/core.py @@ -320,6 +320,7 @@ def __init__(self, active_extensions, cliargs, base_image): self.dockerfile = generate_dockerfile(active_extensions, self.cliargs, base_image) self.image_id = None + self.run_subprocesses = [] def build(self, **kwargs): with tempfile.TemporaryDirectory() as td: @@ -417,7 +418,10 @@ def run(self, command='', **kwargs): print(f"Logging output to file {console_output_file}") print("Executing command: ") print(cmd) - p = subprocess.run(shlex.split(cmd), check=True, stdout=consoleout_fh if console_output_file else None, stderr=subprocess.STDOUT) + p = subprocess.Popen(shlex.split(cmd), stdout=consoleout_fh if console_output_file else None, stderr=subprocess.STDOUT) + self.run_subprocesses.append(p) + p.wait() + self.run_subprocesses.remove(p) return p.returncode except subprocess.CalledProcessError as ex: print("Non-interactive Docker run failed\n", ex) @@ -427,9 +431,11 @@ def run(self, command='', **kwargs): print("Executing command: ") print(cmd) p = pexpect.spawn(cmd) + self.run_subprocesses.append(p) with SIGWINCHPassthrough(p): p.interact() p.close(force=True) + self.run_subprocesses.remove(p) return p.exitstatus except pexpect.ExceptionPexpect as ex: print("Docker run failed\n", ex)