-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwatchdog.py
52 lines (36 loc) · 1.29 KB
/
watchdog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from threading import Thread
import time
import os
class Watchdog(object):
def __init__(self):
self.last_ping = time.time()
self.time_to_stop = False
self.must_die = False
self.thread = Thread(target=self)
self.thread.daemon = True
self.thread.start()
def __call__(self):
while True:
time.sleep(1)
if self.time_to_stop:
return
since_last = time.time() - self.last_ping
if since_last > 10.0:
# OMG OMG OMG!!!!
print("\n\n OMG OMG OMG!!!!!")
print(" Watchdog timer was not pinged frequently enough.")
print(" Exiting with extreme prejudice because we assume a show is hung.\n\n")
print("%f" % since_last)
os._exit(1)
if self.must_die:
print("\n\n Must die set. Exiting")
os._exit(2)
def ping(self):
self.last_ping = time.time()
def stop(self):
self.time_to_stop = True
def manual_reset(self):
print("--------------------------------------------------------")
print(" MANUAL SERVER RESET")
print("--------------------------------------------------------")
self.must_die = True