From 76750fc8a618c46384be879d6549930c1071b753 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 20 May 2020 13:22:26 +0200 Subject: [PATCH] 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. --- test/mavsdk_tests/mavsdk_test_runner.py | 2 ++ test/mavsdk_tests/process_helper.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/mavsdk_tests/mavsdk_test_runner.py b/test/mavsdk_tests/mavsdk_test_runner.py index 8bcc3e083a..b0ba4a8134 100755 --- a/test/mavsdk_tests/mavsdk_test_runner.py +++ b/test/mavsdk_tests/mavsdk_test_runner.py @@ -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, diff --git a/test/mavsdk_tests/process_helper.py b/test/mavsdk_tests/process_helper.py index 0408ec154e..761fc32e41 100644 --- a/test/mavsdk_tests/process_helper.py +++ b/test/mavsdk_tests/process_helper.py @@ -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