Skip to content

Commit 6fff2eb

Browse files
Addressed PR comments from @andy31415
1 parent 2519468 commit 6fff2eb

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

scripts/tests/linux/log_line_processing.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,26 @@ def _io_thread(self):
6363
err_wait = select.poll()
6464
err_wait.register(self.process.stderr, select.POLLIN | select.POLLHUP)
6565

66-
with open(self.output_path, "wt", buffering=1) as f:
66+
with open(self.output_path, "wt", buffering=1) as f: # Enable line buffering for immediate output
6767
f.write("PROCESS START: %s\n" % time.ctime())
6868
f.flush()
6969
while not self.done:
7070
out_changes = out_wait.poll(0.1)
71-
for fd, _ in out_changes:
72-
if fd == self.process.stdout.fileno():
73-
while True:
74-
out_line = self.process.stdout.readline()
75-
if not out_line:
76-
break
77-
f.write(out_line)
78-
f.flush()
79-
self.output_lines.put(out_line)
71+
if self.process.stdout.fileno() in [fd for (fd, _) in out_changes]:
72+
while True:
73+
out_line = self.process.stdout.readline()
74+
if not out_line:
75+
break
76+
f.write(out_line)
77+
f.flush()
78+
self.output_lines.put(out_line)
8079

8180
err_changes = err_wait.poll(0)
82-
for fd, _ in err_changes:
83-
if fd == self.process.stderr.fileno():
84-
err_line = self.process.stderr.readline()
85-
if err_line:
86-
f.write(f"!!STDERR!! : {err_line}")
87-
f.flush()
81+
if self.process.stderr.fileno() in [fd for (fd, _) in err_changes]:
82+
err_line = self.process.stderr.readline()
83+
if err_line:
84+
f.write(f"!!STDERR!! : {err_line}")
85+
f.flush()
8886
f.write("PROCESS END: %s\n" % time.ctime())
8987
f.flush()
9088

@@ -96,7 +94,7 @@ def __enter__(self):
9694
stdout=subprocess.PIPE,
9795
stderr=subprocess.PIPE,
9896
text=True,
99-
bufsize=1,
97+
bufsize=1, # Enable line buffering for immediate output from subprocess
10098
)
10199
self.io_thread = threading.Thread(target=self._io_thread)
102100
self.io_thread.start()

0 commit comments

Comments
 (0)