From db8737a6aab4a745f7d769805f0d79b9f159eff1 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 5 Nov 2016 13:47:27 +0100 Subject: [PATCH] [modules/nic] Add interface type cache to avoid too many open files Repeatedly querying the interface type the way I'm doing right now results in "too many files open" pretty quickly. Obviously, it's a bit of a concern that I am leaking a file descriptor somewhere, but for now, the quickfix is to cache the type (it shouldn't change, anyhow). --- bumblebee/modules/nic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/nic.py b/bumblebee/modules/nic.py index 670d8d4..209d9ed 100644 --- a/bumblebee/modules/nic.py +++ b/bumblebee/modules/nic.py @@ -16,6 +16,7 @@ class Module(bumblebee.module.Module): super(Module, self).__init__(output, config) self._exclude = ( "lo", "virbr", "docker", "vboxnet" ) self._state = "down" + self._typecache = {} def widgets(self): result = [] @@ -55,11 +56,13 @@ class Module(bumblebee.module.Module): def state(self, widget): intf = widget.get("intf") - t = "wireless" if self._iswlan(intf) else "wired" - t = "tunnel" if self._istunnel(intf) else t + if not intf in self._typecache: + t = "wireless" if self._iswlan(intf) else "wired" + t = "tunnel" if self._istunnel(intf) else t + self._typecache[intf] = t - return "{}-{}".format(t, widget.get("state")) + return "{}-{}".format(self._typecache[intf], widget.get("state")) def warning(self, widget): return widget.get("state") != "up"