From f523afda954cdb7c39be5df734430a737b64ec23 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 21 Jul 2021 13:58:53 +0100 Subject: [PATCH] target: Fix deadlock in Target.clear_logcat() Ensure that only once clear_logcat() call is active at once, and just ignore reentrant calls. --- devlib/target.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/devlib/target.py b/devlib/target.py index 3b26a95..1491e6a 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -1759,11 +1759,15 @@ class AndroidTarget(Target): self.remove(dev_path) def clear_logcat(self): - with self.clear_logcat_lock: - if isinstance(self.conn, AdbConnection): - adb_command(self.adb_name, 'logcat -c', timeout=30, adb_server=self.adb_server) - else: - self.execute('logcat -c', timeout=30) + locked = self.clear_logcat_lock.acquire(blocking=False) + if locked: + try: + if isinstance(self.conn, AdbConnection): + adb_command(self.adb_name, 'logcat -c', timeout=30, adb_server=self.adb_server) + else: + self.execute('logcat -c', timeout=30) + finally: + self.clear_logcat_lock.release() def get_logcat_monitor(self, regexps=None): return LogcatMonitor(self, regexps)