MCPcopy
hub / github.com/ModelTC/LightLLM / Watchdog

Class Watchdog

lightllm/utils/watchdog_utils.py:8–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class Watchdog:
9 def __init__(self, timeout):
10 self.timeout = timeout
11 self.last_heartbeat = time.time()
12 self.running = True
13
14 def start(self):
15 self.thread = threading.Thread(target=self.run, daemon=True)
16 self.thread.start()
17
18 def run(self):
19 while self.running:
20 time.sleep(2)
21 if time.time() - self.last_heartbeat > self.timeout:
22 logger.error("Watchdog: Timeout! Task is not responding.")
23 self.handle_timeout()
24
25 def handle_timeout(self):
26 logger.error("Watchdog: time out to exit")
27 import sys
28
29 sys.exit(-1)
30
31 def stop(self):
32 self.running = False
33 self.thread.join()
34
35 def heartbeat(self):
36 self.last_heartbeat = time.time()

Callers 7

workderFunction · 0.90
workerFunction · 0.90
workerFunction · 0.90
workerFunction · 0.90
workerFunction · 0.90
workerFunction · 0.90
workerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected