diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py index 10104862..07d27f1b 100644 --- a/autotests/util/hostapd.py +++ b/autotests/util/hostapd.py @@ -5,6 +5,7 @@ import socket import select import time from gi.repository import GLib +from weakref import WeakValueDictionary from config import ctx chan_freq_map = [ @@ -29,7 +30,7 @@ ctrl_count = 0 mainloop = GLib.MainLoop() class HostapdCLI(object): - _instances = {} + _instances = WeakValueDictionary() def __new__(cls, config=None, *args, **kwargs): hapd = ctx.hostapd[config] @@ -38,8 +39,10 @@ class HostapdCLI(object): config = hapd.config if not config in cls._instances.keys(): - cls._instances[config] = object.__new__(cls, *args, **kwargs) - cls._instances[config]._initialized = False + obj = object.__new__(cls, *args, **kwargs) + obj._initialized = False + + cls._instances[config] = obj return cls._instances[config] @@ -123,13 +126,6 @@ class HostapdCLI(object): except: pass - HostapdCLI._instances[self.config] = None - - # Check if this is the final instance - destroy = len([hapd for hapd in HostapdCLI._instances.values() if hapd is not None]) == 0 - if destroy: - HostapdCLI._instances = {} - def set_value(self, key, value): cmd = self.cmdline + ['set', key, value] ctx.start_process(cmd).wait() diff --git a/tools/test-runner b/tools/test-runner index 8b244e99..b7a283d1 100755 --- a/tools/test-runner +++ b/tools/test-runner @@ -541,13 +541,6 @@ class Hostapd: except: print("Failed to remove %s" % self.global_ctrl_iface) - for hapd in self.instances: - if not hapd.cli: - continue - - hapd.cli._instances[hapd.config] = None - hapd.cli = None - self.instances = None # Hostapd may have already been stopped