mavsdk_tests: collect buffered up stdout output

Somehow only subprocess.stdout.readline() works at a time. In order not
to miss out on some of the stdout output, we need to collect it all at
the end. Also, we can stop using readline() for processes that have quit
already.
This commit is contained in:
Julian Oes 2020-05-20 13:22:26 +02:00
parent 1f57d63503
commit 76750fc8a6
2 changed files with 9 additions and 8 deletions

View File

@ -341,6 +341,8 @@ class Tester:
is_success = False
self.stop_runners()
# Collect what was left in output buffers.
self.collect_runner_output()
self.stop_combined_log()
result = {'success': is_success,

View File

@ -53,7 +53,7 @@ class Runner:
cwd=self.cwd,
env=self.env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
universal_newlines=True
)
@ -63,11 +63,12 @@ class Runner:
def process_output(self) -> None:
assert self.process.stdout is not None
while not self.stop_thread.is_set():
while True:
line = self.process.stdout.readline()
if line == "\n":
continue
if not line:
if not line and \
(self.stop_thread.is_set() or self.poll is not None):
break
if not line or line == "\n":
continue
self.output_queue.put(line)
self.log_fd.write(line)
@ -99,8 +100,6 @@ class Runner:
if not self.stop_thread:
return 0
self.stop_thread.set()
returncode = self.process.poll()
if returncode is None:
@ -123,8 +122,8 @@ class Runner:
print("{} exited with {}".format(
self.cmd, self.process.returncode))
self.stop_thread.set()
self.thread.join()
self.log_fd.close()
return self.process.returncode