Skip to content

Commit 96d516b

Browse files
committed
Detect End Of File on stdout and stderr while reading
The previous code lifelocked on the EOF markers, i.e., empty strings. Signed-off-by: Stefan Marr <git@stefan-marr.de>
1 parent 61d99cc commit 96d516b

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

rebench/subprocess_with_timeout.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,39 @@ def process_output(self, proc):
9191
self.stdout_result = ""
9292
self.stderr_result = ""
9393

94+
stdout_eof = False
95+
stderr_eof = False
96+
9497
while True:
9598
reads = []
9699

97-
if proc.stdout and not proc.stdout.closed:
100+
if proc.stdout and not proc.stdout.closed and not stdout_eof:
98101
reads.append(proc.stdout.fileno())
99-
if self._stderr == PIPE and proc.stderr and not proc.stderr.closed:
102+
if (self._stderr == PIPE and
103+
proc.stderr and
104+
not proc.stderr.closed and
105+
not stderr_eof):
100106
reads.append(proc.stderr.fileno())
101107

102108
if not reads:
103109
break
104110

105-
ret = select(reads, [], [])
111+
ret = select(reads, [], [], 0.1)
106112
for file_no in ret[0]:
107113
if file_no == proc.stdout.fileno():
108114
read = output_as_str(proc.stdout.readline())
109-
sys.stdout.write(read)
110-
self.stdout_result += read
115+
if read == "":
116+
stdout_eof = True
117+
else:
118+
sys.stdout.write(read)
119+
self.stdout_result += read
111120
if self._stderr == PIPE and file_no == proc.stderr.fileno():
112121
read = output_as_str(proc.stderr.readline())
113-
sys.stderr.write(read)
114-
self.stderr_result += read
122+
if read == "":
123+
stderr_eof = True
124+
else:
125+
sys.stderr.write(read)
126+
self.stderr_result += read
115127
else:
116128
stdout_r, stderr_r = proc.communicate()
117129
self.stdout_result = output_as_str(stdout_r)

0 commit comments

Comments
 (0)