forked from remotv/controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatchdog.py
30 lines (21 loc) · 801 Bytes
/
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
#TODO: Count restarts during a time period, and terminate if too high.
# Add a vital flag to a process, if restart fails, program will terminate.
#
from threading import Thread
import logging
log = logging.getLogger('RemoTV.watchdog')
watches={}
def watch():
global watches
for (name, process) in watches.items():
if not process[0].is_alive():
log.error("Process "+name+" not running, restarting")
start(name, process[1], *process[2], **process[3])
def start(name, startFunction, *args, **kwargs):
global watches
thread = Thread(target=startFunction, args=args, kwargs=kwargs)
thread.setDaemon(True)
thread.start()
watches[name] = [thread, startFunction, args, kwargs]
def stop(name):
del watches[name]