Merge pull request #176 from bjackman/logcat-docs
utils/anroid: Documentation for LogcatMonitor
diff --git a/devlib/utils/android.py b/devlib/utils/android.py
index 1f1f762..ce1ab0b 100644
--- a/devlib/utils/android.py
+++ b/devlib/utils/android.py
@@ -286,6 +286,10 @@
"""
# TODO this is a hacky way to issue a adb command to all listed devices
+ # Ensure server is started so the 'daemon started successfully' message
+ # doesn't confuse the parsing below
+ adb_command(None, 'start-server', adb_server=adb_server)
+
# The output of calling adb devices consists of a heading line then
# a list of the devices sperated by new line
# The last line is a blank new line. in otherwords, if there is a device found
@@ -555,6 +559,7 @@
self.target = target
+ self._started = threading.Event()
self._stopped = threading.Event()
self._match_found = threading.Event()
@@ -596,12 +601,21 @@
logger.debug('logcat command ="{}"'.format(logcat_cmd))
self._logcat = self.target.background(logcat_cmd)
+ self._started.set()
+
while not self._stopped.is_set():
line = self._logcat.stdout.readline(1024)
if line:
self._add_line(line)
def stop(self):
+ if not self.is_alive():
+ logger.warning('LogcatMonitor.stop called before start')
+ return
+
+ # Make sure we've started before we try to kill anything
+ self._started.wait()
+
# Kill the underlying logcat process
# This will unblock self._logcat.stdout.readline()
host.kill_children(self._logcat.pid)
@@ -632,7 +646,7 @@
with self._datalock:
while not self._lines.empty():
self._lines.get()
-
+
with open(self._logfile, 'w') as fh:
pass