-
Notifications
You must be signed in to change notification settings - Fork 8
/
run.py
40 lines (31 loc) · 840 Bytes
/
run.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
"""This is a bad hack, or an alternative as
I'd like to put it, to a cron job shutting
down faqbot and restarting it every so often.
The reason for this is because IDLE is finicky
and our current system doesn't know how to catch
disconnects, so we just restart before stuff
stop working.
"""
import subprocess
import time
import psutil
import signal
import sys
def kill(proc_pid):
process = psutil.Process(proc_pid)
for proc in process.children(recursive=True):
proc.kill()
process.kill()
VERBOSE = True
DELAY = 1200 # seconds, or 20 minutes
lastproc = None
# Loop infinitely.
while True:
# Start the app.
p = subprocess.Popen(["python", "app.py"])
lasproc = p.pid
print '[Runner] Started at', p.pid
time.sleep(DELAY) # Wait a minute.
if VERBOSE:
print "Killing {}".format(p.pid)
kill(p.pid) # KILL.