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>
This commit is contained in:
parent
4cdbe3f2b9
commit
8f5a0bd9b4
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue