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
+2
View File
@@ -341,6 +341,8 @@ class Tester:
is_success = False is_success = False
self.stop_runners() self.stop_runners()
# Collect what was left in output buffers.
self.collect_runner_output()
self.stop_combined_log() self.stop_combined_log()
result = {'success': is_success, result = {'success': is_success,
+7 -8
View File
@@ -53,7 +53,7 @@ class Runner:
cwd=self.cwd, cwd=self.cwd,
env=self.env, env=self.env,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.PIPE,
universal_newlines=True universal_newlines=True
) )
@@ -63,11 +63,12 @@ class Runner:
def process_output(self) -> None: def process_output(self) -> None:
assert self.process.stdout is not None assert self.process.stdout is not None
while not self.stop_thread.is_set(): while True:
line = self.process.stdout.readline() line = self.process.stdout.readline()
if line == "\n": if not line and \
continue (self.stop_thread.is_set() or self.poll is not None):
if not line: break
if not line or line == "\n":
continue continue
self.output_queue.put(line) self.output_queue.put(line)
self.log_fd.write(line) self.log_fd.write(line)
@@ -99,8 +100,6 @@ class Runner:
if not self.stop_thread: if not self.stop_thread:
return 0 return 0
self.stop_thread.set()
returncode = self.process.poll() returncode = self.process.poll()
if returncode is None: if returncode is None:
@@ -123,8 +122,8 @@ class Runner:
print("{} exited with {}".format( print("{} exited with {}".format(
self.cmd, self.process.returncode)) self.cmd, self.process.returncode))
self.stop_thread.set()
self.thread.join() self.thread.join()
self.log_fd.close() self.log_fd.close()
return self.process.returncode return self.process.returncode