From e9736c0b9b54966f6cbfa7f71ce554788e6b9e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E9=A6=99ROS?= <87068644+fishros@users.noreply.github.com> Date: Sun, 8 Sep 2024 21:46:47 +0800 Subject: [PATCH] fix: https://fishros.org.cn/forum/topic/2989 --- tools/base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/base.py b/tools/base.py index 67cb2be..af78154 100644 --- a/tools/base.py +++ b/tools/base.py @@ -992,6 +992,7 @@ def log_callback(log,log_type): msg = 'code:{}'.format(code) if code == 0: msg="success" + self.ret_code = code if code==0: self.bar.finsh('CMD Result:{}'.format(msg),'\033[37m') @@ -999,7 +1000,6 @@ def log_callback(log,log_type): self.bar.finsh('CMD Result:{}'.format(msg),'\033[31m') - self.ret_code = code self.ret_out = out self.ret_err = err self.ret_ok = True @@ -1008,10 +1008,14 @@ def run_command(self,executable='/bin/sh'): self.command_thread = threading.Thread(target=self.command_thread) self.command_thread.start() time.sleep(0.5) # 等待线程启动 - while self.is_command_finish()==-1 and not self.ret_ok: + while self.is_command_finish()==-1: self.bar.update_time() time.sleep(0.1) + start_time = time.time() + while not self.ret_ok and time.time()-start_time < 2.0: # 2s timeout wait command_thread end + time.sleep(0.1) + Tracking.put_cmd_result(self.ret_code,self.ret_out,self.ret_err,self.command) return (self.ret_code,self.ret_out,self.ret_err)