Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, signal, threading
- class WatchDog():
- def __init__(self, timeout=5):
- self.timeout = timeout
- self._t = None
- def do_expire(self):
- hostname = "8.8.8.8"
- response = os.system("ping -c 1 " + hostname)
- if response == 0:
- self.refresh()
- else:
- print("Pinging 8.8.8.8 yielded no response!")
- hostname = "8.8.4.4"
- response = os.system("ping -c 1 " + hostname)
- if response == 0:
- self.refresh()
- else:
- print("Pinging 8.8.4.4 yielded no response!")
- def _expire(self):
- print("\nWatchdog expire")
- self.do_expire()
- def start(self):
- if self._t is None:
- self._t = threading.Timer(self.timeout, self._expire)
- self._t.start()
- def stop(self):
- if self._t is not None:
- self._t.cancel()
- self._t = None
- def refresh(self):
- if self._t is not None:
- self.stop()
- self.start()
- wd = WatchDog()
- wd.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement