Mesa (main): gitlab-ci: serial close can leave an active read
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Dec 3 23:52:02 UTC 2021
Module: Mesa
Branch: main
Commit: eb0b08ea1aac2e29f5c2fa46da905dd7fb83f044
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb0b08ea1aac2e29f5c2fa46da905dd7fb83f044
Author: Ilia Mirkin <imirkin at alum.mit.edu>
Date: Thu Dec 2 01:30:45 2021 -0500
gitlab-ci: serial close can leave an active read
So instead cancel the read first, and then close. Make sure the
serial-reading properly detects this cancelled condition under all
circumstances and exits.
Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14033>
---
.gitlab-ci/bare-metal/serial_buffer.py | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/.gitlab-ci/bare-metal/serial_buffer.py b/.gitlab-ci/bare-metal/serial_buffer.py
index 28565ebf4df..710e7867782 100755
--- a/.gitlab-ci/bare-metal/serial_buffer.py
+++ b/.gitlab-ci/bare-metal/serial_buffer.py
@@ -28,7 +28,6 @@ import serial
import threading
import time
-
class SerialBuffer:
def __init__(self, dev, filename, prefix, timeout = None):
self.filename = filename
@@ -36,7 +35,7 @@ class SerialBuffer:
if dev:
self.f = open(filename, "wb+")
- self.serial = serial.Serial(dev, 115200, timeout=timeout if timeout else 10)
+ self.serial = serial.Serial(dev, 115200, timeout=timeout)
else:
self.f = open(filename, "rb")
self.serial = None
@@ -63,9 +62,11 @@ class SerialBuffer:
def close(self):
self.closing = True
if self.serial:
- self.serial.close()
+ self.serial.cancel_read()
self.read_thread.join()
self.lines_thread.join()
+ if self.serial:
+ self.serial.close()
# 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.
@@ -73,18 +74,16 @@ class SerialBuffer:
greet = "Serial thread reading from %s\n" % self.dev
self.byte_queue.put(greet.encode())
- while True:
+ while not self.closing:
try:
b = self.serial.read()
- if len(b) > 0:
- self.byte_queue.put(b)
- elif self.timeout:
- self.byte_queue.put(self.sentinel)
+ if len(b) == 0:
break
+ self.byte_queue.put(b)
except Exception as err:
print(self.prefix + str(err))
- self.byte_queue.put(self.sentinel)
break
+ self.byte_queue.put(self.sentinel)
# Thread that just reads the bytes from the file of serial output that some
# other process is appending to.
More information about the mesa-commit
mailing list