From 0c9177cb7958b1c48f8b3bd5b7fb3ac45df8564f Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Fri, 18 Nov 2016 19:47:28 +0100 Subject: [PATCH] [modules/ping] Allow recovery from unreachable Due to a bug, when the destination was unreachable, the checking thread would terminate, effectively keeping the widget stuck in "unreachable" mode. Now, enable recovery by keeping the thread running even if the target is not reachable for some time. --- bumblebee/modules/ping.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/bumblebee/modules/ping.py b/bumblebee/modules/ping.py index e188749..20fec39 100644 --- a/bumblebee/modules/ping.py +++ b/bumblebee/modules/ping.py @@ -41,20 +41,19 @@ def get_rtt(obj): res = subprocess.check_output(shlex.split("ping -n -q -c {} -W {} {}".format( obj.get("rtt-probes"), obj.get("rtt-timeout"), obj.get("address") ))) + obj.set("rtt-unreachable", False) + + for line in res.decode().split("\n"): + if not line.startswith("rtt"): continue + m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line) + + obj.set("rtt-min", float(m.group(1))) + obj.set("rtt-avg", float(m.group(2))) + obj.set("rtt-max", float(m.group(3))) + obj.set("rtt-unit", m.group(5)) except Exception as e: obj.set("rtt-unreachable", True) - break - obj.set("rtt-unreachable", False) - - for line in res.decode().split("\n"): - if not line.startswith("rtt"): continue - m = re.search(r'([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+)\s+(\S+)', line) - - obj.set("rtt-min", float(m.group(1))) - obj.set("rtt-avg", float(m.group(2))) - obj.set("rtt-max", float(m.group(3))) - obj.set("rtt-unit", m.group(5)) class Module(bumblebee.module.Module): def __init__(self, output, config, alias):