From b7044d37085d8d2987c5f69181a1f65e614950e6 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 18 Feb 2021 13:49:09 +1100 Subject: [PATCH] autotest: remove use of global expect_list --- Tools/autotest/common.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index c030a50a6363b..a7ea433d1816f 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -62,10 +62,6 @@ mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT_INT ] -# a list of pexpect objects to read while waiting for -# messages. This keeps the output to stdout flowing -expect_list = [] - # get location of scripts testdir = os.path.dirname(os.path.realpath(__file__)) @@ -1242,6 +1238,8 @@ def __init__(self, self.rc_thread_should_quit = False self.rc_queue = Queue.Queue() + self.expect_list = [] + def __del__(self): if self.rc_thread is not None: self.progress("Joining thread in __del__") @@ -2183,24 +2181,20 @@ def try_symlink_tlog(self): ################################################# def expect_list_clear(self): """clear the expect list.""" - global expect_list - for p in expect_list[:]: - expect_list.remove(p) + for p in self.expect_list[:]: + self.expect_list.remove(p) def expect_list_extend(self, list_to_add): """Extend the expect list.""" - global expect_list - expect_list.extend(list_to_add) + self.expect_list.extend(list_to_add) def expect_list_add(self, item): """Extend the expect list.""" - global expect_list - expect_list.extend([item]) + self.expect_list.extend([item]) def expect_list_remove(self, item): """Remove item from the expect list.""" - global expect_list - expect_list.remove(item) + self.expect_list.remove(item) def heartbeat_interval_ms(self): c = self.context_get() @@ -2244,8 +2238,7 @@ def do_heartbeats(self, force=False): 0) def drain_all_pexpects(self): - global expect_list - for p in expect_list: + for p in self.expect_list: util.pexpect_drain(p) def idle_hook(self, mav): @@ -2279,8 +2272,7 @@ def write_msg_to_tlog(self, msg): def expect_callback(self, e): """Called when waiting for a expect pattern.""" - global expect_list - for p in expect_list: + for p in self.expect_list: if p == e: continue util.pexpect_drain(p)