Avoid deadlock in get_e2e_artifacts (#3500)
You can't use `process.wait()` with pipes.
Fixes https://github.com/google/iree/issues/3499
diff --git a/scripts/utils.py b/scripts/utils.py
index 3b6f547..18d9f8f 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -32,31 +32,26 @@
return '\n'.join([' | '.join(row) for row in rows])
-def check_and_get_output(command: Sequence[str],
- dry_run: bool = False,
- log_stderr: bool = True,
- stderr_filters: Sequence[str] = ()):
+def check_and_get_output_lines(command: Sequence[str],
+ dry_run: bool = False,
+ log_stderr: bool = True,
+ stderr_filters: Sequence[str] = ()):
print(f'Running: `{" ".join(command)}`')
if dry_run:
return None, None
- process = subprocess.Popen(command,
- bufsize=1,
- stderr=subprocess.PIPE,
- stdout=subprocess.PIPE,
- universal_newlines=True)
- process.wait()
- stdout = [line.strip(os.linesep) for line in process.stdout]
- stderr = [line.strip(os.linesep) for line in process.stderr]
+ process = subprocess.run(command,
+ stderr=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ universal_newlines=True)
if log_stderr:
- for line in stderr:
+ for line in process.stderr.splitlines():
if not any(re.match(pattern, line) for pattern in stderr_filters):
print(line)
- if process.returncode != 0:
- raise subprocess.CalledProcessError(process.returncode, ' '.join(command))
+ process.check_returncode()
- return stdout, stderr
+ return process.stdout.splitlines()
def get_test_targets(test_suite_path: str):
@@ -66,10 +61,10 @@
# unfortunately the same as the return code for a bazel configuration error.
target_dir = test_suite_path.split(':')[0]
query = ['bazel', 'query', f'{target_dir}/...']
- targets, _ = check_and_get_output(query, stderr_filters=BAZEL_FILTERS)
+ targets = check_and_get_output_lines(query, stderr_filters=BAZEL_FILTERS)
if test_suite_path not in targets:
return []
query = ['bazel', 'query', f'tests({test_suite_path})']
- tests, _ = check_and_get_output(query, stderr_filters=BAZEL_FILTERS)
+ tests = check_and_get_output_lines(query, stderr_filters=BAZEL_FILTERS)
return tests