[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).
This commit is contained in:
Tobias Witek 2016-11-05 13:47:27 +01:00
parent a9a62a738d
commit db8737a6aa

View file

@ -16,6 +16,7 @@ class Module(bumblebee.module.Module):
super(Module, self).__init__(output, config) super(Module, self).__init__(output, config)
self._exclude = ( "lo", "virbr", "docker", "vboxnet" ) self._exclude = ( "lo", "virbr", "docker", "vboxnet" )
self._state = "down" self._state = "down"
self._typecache = {}
def widgets(self): def widgets(self):
result = [] result = []
@ -55,11 +56,13 @@ class Module(bumblebee.module.Module):
def state(self, widget): def state(self, widget):
intf = widget.get("intf") 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): def warning(self, widget):
return widget.get("state") != "up" return widget.get("state") != "up"