[CI] Read subprocess stdout on a background thread to avoid EOF deadlock (#36673)
This commit is contained in:
@@ -223,10 +223,18 @@ def run_unittest_files(
|
||||
errors="ignore", # Ignore non-UTF-8 bytes to prevent UnicodeDecodeError
|
||||
)
|
||||
output_lines = []
|
||||
for line in process.stdout:
|
||||
logger.info(line.rstrip())
|
||||
output_lines.append(line)
|
||||
|
||||
def read_output():
|
||||
for line in process.stdout:
|
||||
logger.info(line.rstrip())
|
||||
output_lines.append(line)
|
||||
|
||||
# Read stdout on a background thread so the main thread won't block on EOF.
|
||||
reader_thread = threading.Thread(target=read_output, daemon=True)
|
||||
reader_thread.start()
|
||||
process.wait()
|
||||
# Bounded wait for the reader to finish.
|
||||
reader_thread.join(timeout=60)
|
||||
else:
|
||||
process = subprocess.Popen(cmd, stdout=None, stderr=None)
|
||||
process.wait()
|
||||
|
||||
Reference in New Issue
Block a user