eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit 1a0148617077868d35ac775449a88fde7d69749e
parent 4657bd55f56209388d284bf1ef72367d366fcdff
Author: James Prestwood <prestwoj@gmail.com>
Date:   Thu, 26 Aug 2021 13:33:31 -0700

auto-t: hwsim.py: turn Hwsim into singleton (per-namespace)

This prevents reallocation of new Hwsim classes on each call if one
already exists. This is a bit more efficient on memory.

Diffstat:
Mautotests/util/hwsim.py | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/autotests/util/hwsim.py b/autotests/util/hwsim.py @@ -3,6 +3,7 @@ import dbus import sys import collections +from weakref import WeakValueDictionary from abc import ABCMeta, abstractmethod from enum import Enum @@ -297,7 +298,25 @@ class RadioList(collections.Mapping): return obj class Hwsim(iwd.AsyncOpAbstract): + _instances = WeakValueDictionary() + + def __new__(cls, namespace=ctx): + name = namespace.name + + if name not in cls._instances.keys(): + obj = object.__new__(cls) + obj._initialized = False + + cls._instances[name] = obj + + return cls._instances[name] + def __init__(self, namespace=ctx): + if self._initialized: + return + + self._initialized = True + self._bus = namespace.get_bus() self._rule_manager_if = dbus.Interface(