Merge "Catch Encoding exception and ignore the exception line in logger." am: 8a0b78e594 am: 063ed97fd9 am: 270603e7c4 am: 6f1675800a
Original change: https://android-review.googlesource.com/c/platform/tools/test/openhst/+/1438372
Change-Id: I75eed892445a0bb310ce2b8487071c1f33ac8a4c
diff --git a/stress_test.py b/stress_test.py
index 1576fbe..2ff487a 100644
--- a/stress_test.py
+++ b/stress_test.py
@@ -249,6 +249,7 @@
last_line = None
should_log = True
first_run = True
+ skip_exception_line = False
self.lock.acquire()
last_run_time = 0
while self.restart_process:
@@ -280,6 +281,10 @@
if last_line == line:
should_log = True
continue
+ elif skip_exception_line:
+ # ignore the last line which caused UnicodeEncodeError
+ skip_exception_line = False
+ continue
if self.output_fp:
self.output_fp.write(line.decode("utf-8", "backslashreplace").rstrip())
@@ -291,6 +296,9 @@
if self.looking:
event.ScanForEvent(line, lock=self.lock)
last_line = line
+ except UnicodeEncodeError:
+ logging.exception("UnicodeEncodeError on running logger process")
+ skip_exception_line = True
except: # pylint:disable=bare-except
logging.exception("Exception encountered running process")
finally:
@@ -300,6 +308,7 @@
self.process.send_signal(signal.SIGTERM)
should_log = False
self.lock.acquire()
+
self.lock.release()
if pexpect:
if self.process.exitstatus is not None: