Mercurial > ~darius > hgwebdir.cgi > adslstats
comparison speedcheck.py @ 40:947fa4062b01 default tip
Don't blow up if ping fails.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 29 Nov 2022 11:53:06 +1030 |
parents | 1a87c79cf103 |
children |
comparison
equal
deleted
inserted
replaced
39:1a87c79cf103 | 40:947fa4062b01 |
---|---|
77 p = subprocess.Popen(['ping', '-c', '5', '-t', '8', '-q', host], stdout = subprocess.PIPE) | 77 p = subprocess.Popen(['ping', '-c', '5', '-t', '8', '-q', host], stdout = subprocess.PIPE) |
78 stdout, stderr = p.communicate() | 78 stdout, stderr = p.communicate() |
79 l = stdout.decode('ascii', 'ignore').split('\n') | 79 l = stdout.decode('ascii', 'ignore').split('\n') |
80 if len(l) != 6: | 80 if len(l) != 6: |
81 print('Unable to parse ping line:', l) | 81 print('Unable to parse ping line:', l) |
82 return float('nan'), float('nan') | |
82 xx, xx, xx, plossline, latline, xx = l | 83 xx, xx, xx, plossline, latline, xx = l |
83 ploss = re.match('.* received, ([0-9.]+)% packet loss', plossline) | 84 ploss = re.match('.* received, ([0-9.]+)% packet loss', plossline) |
84 if ploss is not None: | 85 if ploss is not None: |
85 ploss = float(ploss.groups()[0]) | 86 ploss = float(ploss.groups()[0]) |
86 latency = re.match('.*std-?dev = [0-9.]+/([0-9.]+)/.* ms', latline) | 87 latency = re.match('.*std-?dev = [0-9.]+/([0-9.]+)/.* ms', latline) |