Mesa (main): ci/bare-metal: Close serial and join serial threads before exit.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Nov 10 21:09:10 UTC 2021
Module: Mesa
Branch: main
Commit: 8f5a0bd9b40e2b1239da3e17437115c78fb14bba
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8f5a0bd9b40e2b1239da3e17437115c78fb14bba
Author: Emma Anholt <emma at anholt.net>
Date: Wed Oct 20 17:16:54 2021 -0700
ci/bare-metal: Close serial and join serial threads before exit.
This should fix the intermittent (~1/week) cheza failure where python
complains that a thread tried to do stdio while the main thread has
exited.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13462>
---
.gitlab-ci/bare-metal/cros_servo_run.py | 10 +++++++++-
.gitlab-ci/bare-metal/fastboot_run.py | 4 ++++
.gitlab-ci/bare-metal/serial_buffer.py | 12 +++++++++++-
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/.gitlab-ci/bare-metal/cros_servo_run.py b/.gitlab-ci/bare-metal/cros_servo_run.py
index 995e1121066..23cebb0abee 100755
--- a/.gitlab-ci/bare-metal/cros_servo_run.py
+++ b/.gitlab-ci/bare-metal/cros_servo_run.py
@@ -50,12 +50,18 @@ class CrosServoRun:
target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(),))
self.iter_feed_cpu.start()
+ def close(self):
+ self.ec_ser.close()
+ self.cpu_ser.close()
+ self.iter_feed_ec.join()
+ self.iter_feed_cpu.join()
+
# Feed lines from our serial queues into the merged queue, marking when our
# input is done.
def iter_feed_queue(self, it):
for i in it:
self.serial_queue.put(i)
- self.serial_queue.put(sentinel)
+ self.serial_queue.put(self.sentinel)
# Return the next line from the queue, counting how many threads have
# terminated and joining when done
@@ -179,6 +185,8 @@ def main():
# power down the CPU on the device
servo.ec_write("power off\n")
+ servo.close()
+
sys.exit(retval)
diff --git a/.gitlab-ci/bare-metal/fastboot_run.py b/.gitlab-ci/bare-metal/fastboot_run.py
index 3654c7c8088..9fb2cb36b2b 100755
--- a/.gitlab-ci/bare-metal/fastboot_run.py
+++ b/.gitlab-ci/bare-metal/fastboot_run.py
@@ -36,6 +36,9 @@ class FastbootRun:
self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ", timeout=600)
self.fastboot="fastboot boot -s {ser} artifacts/fastboot.img".format(ser=args.fbserial)
+ def close(self):
+ self.ser.close()
+
def print_error(self, message):
RED = '\033[0;31m'
NO_COLOR = '\033[0m'
@@ -111,6 +114,7 @@ def main():
while True:
retval = fastboot.run()
+ fastboot.close()
if retval != 2:
break
diff --git a/.gitlab-ci/bare-metal/serial_buffer.py b/.gitlab-ci/bare-metal/serial_buffer.py
index 70f37709752..28565ebf4df 100755
--- a/.gitlab-ci/bare-metal/serial_buffer.py
+++ b/.gitlab-ci/bare-metal/serial_buffer.py
@@ -39,12 +39,14 @@ class SerialBuffer:
self.serial = serial.Serial(dev, 115200, timeout=timeout if timeout else 10)
else:
self.f = open(filename, "rb")
+ self.serial = None
self.byte_queue = queue.Queue()
self.line_queue = queue.Queue()
self.prefix = prefix
self.timeout = timeout
self.sentinel = object()
+ self.closing = False
if self.dev:
self.read_thread = threading.Thread(
@@ -58,6 +60,13 @@ class SerialBuffer:
target=self.serial_lines_thread_loop, daemon=True)
self.lines_thread.start()
+ def close(self):
+ self.closing = True
+ if self.serial:
+ self.serial.close()
+ self.read_thread.join()
+ self.lines_thread.join()
+
# Thread that just reads the bytes from the serial device to try to keep from
# buffer overflowing it. If nothing is received in 1 minute, it finalizes.
def serial_read_thread_loop(self):
@@ -83,12 +92,13 @@ class SerialBuffer:
greet = "Serial thread reading from %s\n" % self.filename
self.byte_queue.put(greet.encode())
- while True:
+ while not self.closing:
line = self.f.readline()
if line:
self.byte_queue.put(line)
else:
time.sleep(0.1)
+ self.byte_queue.put(self.sentinel)
# Thread that processes the stream of bytes to 1) log to stdout, 2) log to
# file, 3) add to the queue of lines to be read by program logic
More information about the mesa-commit
mailing list