mirror of
https://github.com/ARM-software/devlib.git
synced 2025-04-18 07:40:04 +01: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.target = target
|
||||||
|
|
||||||
|
self._started = threading.Event()
|
||||||
self._stopped = threading.Event()
|
self._stopped = threading.Event()
|
||||||
self._match_found = threading.Event()
|
self._match_found = threading.Event()
|
||||||
|
|
||||||
@ -584,12 +585,21 @@ class LogcatMonitor(threading.Thread):
|
|||||||
logger.debug('logcat command ="{}"'.format(logcat_cmd))
|
logger.debug('logcat command ="{}"'.format(logcat_cmd))
|
||||||
self._logcat = self.target.background(logcat_cmd)
|
self._logcat = self.target.background(logcat_cmd)
|
||||||
|
|
||||||
|
self._started.set()
|
||||||
|
|
||||||
while not self._stopped.is_set():
|
while not self._stopped.is_set():
|
||||||
line = self._logcat.stdout.readline(1024)
|
line = self._logcat.stdout.readline(1024)
|
||||||
if line:
|
if line:
|
||||||
self._add_line(line)
|
self._add_line(line)
|
||||||
|
|
||||||
def stop(self):
|
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
|
# Kill the underlying logcat process
|
||||||
# This will unblock self._logcat.stdout.readline()
|
# This will unblock self._logcat.stdout.readline()
|
||||||
host.kill_children(self._logcat.pid)
|
host.kill_children(self._logcat.pid)
|
||||||
@ -620,7 +630,7 @@ class LogcatMonitor(threading.Thread):
|
|||||||
with self._datalock:
|
with self._datalock:
|
||||||
while not self._lines.empty():
|
while not self._lines.empty():
|
||||||
self._lines.get()
|
self._lines.get()
|
||||||
|
|
||||||
with open(self._logfile, 'w') as fh:
|
with open(self._logfile, 'w') as fh:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user