mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
Merge pull request #175 from bjackman/logcat-race
Fix race in LogcatMonitor
This commit is contained in:
commit
e1ec1eacfb
@ -549,6 +549,7 @@ class LogcatMonitor(threading.Thread):
|
||||
|
||||
self.target = target
|
||||
|
||||
self._started = threading.Event()
|
||||
self._stopped = threading.Event()
|
||||
self._match_found = threading.Event()
|
||||
|
||||
@ -584,12 +585,21 @@ class LogcatMonitor(threading.Thread):
|
||||
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)
|
||||
@ -620,7 +630,7 @@ class LogcatMonitor(threading.Thread):
|
||||
with self._datalock:
|
||||
while not self._lines.empty():
|
||||
self._lines.get()
|
||||
|
||||
|
||||
with open(self._logfile, 'w') as fh:
|
||||
pass
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user