Eclectic Media Git pingstats / d8eb484
Made keyboard interrupt cleaner Ariana Giroux 1 year, 10 months ago
1 changed file(s) with 20 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3232
3333 print('Waiting for first ping...') # Notify user in case of high ping
3434
35 while 1:
36 time_start = time.time()
35 try:
36 while 1:
37 time_start = time.time()
3738
38 temp_file = NamedTemporaryFile()
39 process = Popen(['ping', '-c 1', parsed.address], stdout=temp_file)
39 temp_file = NamedTemporaryFile()
40 process = Popen(['ping', '-c 1', parsed.address], stdout=temp_file)
4041
41 process.wait()
42 process.wait()
4243
43 with open(temp_file.name) as tf:
44 with open(temp_file.name) as tf:
4445
45 for line in tf:
46 if line.lower().count('ttl'):
46 for line in tf:
47 if line.lower().count('ttl'):
4748
48 if len(y) >= 70:
49 y.pop(0)
49 if len(y) >= 70:
50 y.pop(0)
5051
51 y.append(float(line.split('time=')[1].split(' ')[0]))
52 y.append(float(line.split('time=')[1].split(' ')[0]))
5253
53 elif line.lower().count('timeout'):
54 y = -10
54 elif line.lower().count('timeout'):
55 y = -10
5556
56 if time.time() - time_start < 0.5: # Wait for time if no time elapsed
57 time.sleep(0.5 - (time.time() - time_start))
57 if time.time() - time_start < 0.5: # Wait for time if no time elapsed
58 time.sleep(0.5 - (time.time() - time_start))
5859
59 system('clear' if not name == 'nt' else 'cls')
60 plot(y)
60 system('clear' if not name == 'nt' else 'cls')
61 plot(y)
62 except KeyboardInterrupt:
63 pass
6164
6265
6366 if __name__ == '__main__':