Skip to content

Commit 48eeda9

Browse files
read from stdout and stderr concurrently
Co-authored-by: Copilot <[email protected]>
1 parent f262f29 commit 48eeda9

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

app/get_knowledge_base.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,24 @@ def run_command(command, label):
4242
bufsize=1
4343
)
4444

45-
# log stdout
46-
for line in iter(process.stdout.readline, ''):
47-
if line.strip():
48-
logging.info(f"{label}: {line.rstrip()}")
49-
50-
# log stderr
51-
for line in iter(process.stderr.readline, ''):
52-
if line.strip():
53-
logging.error(f"{label}: {line.rstrip()}")
54-
55-
# Wait for process to complete and check return code
56-
return_code = process.wait()
57-
if return_code != 0:
58-
raise subprocess.CalledProcessError(return_code, command)
59-
45+
# Read both stdout and stderr concurrently
46+
stdout, stderr = process.communicate()
47+
48+
# Log stdout
49+
if stdout:
50+
for line in stdout.splitlines():
51+
if line.strip():
52+
logging.info(f"{label}: {line}")
53+
54+
# Log stderr
55+
if stderr:
56+
for line in stderr.splitlines():
57+
if line.strip():
58+
logging.error(f"{label}: {line}")
59+
60+
# Check return code
61+
if process.returncode != 0:
62+
raise subprocess.CalledProcessError(process.returncode, command)
6063
def run_prebuild_script():
6164
""" Run the defang-docs repo prebuild script"""
6265

0 commit comments

Comments
 (0)