-
Notifications
You must be signed in to change notification settings - Fork 3
/
restart.py
executable file
·35 lines (27 loc) · 1005 Bytes
/
restart.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
#!/usr/bin/env python3
import psutil
import subprocess
import signal
import os
import time
flask_apps = [p.info for p in psutil.process_iter(attrs=['pid', 'name']) if 'flask' in p.info['name']]
print(flask_apps)
for f in flask_apps:
pid = f['pid']
print("killing pid {}".format(pid))
os.kill(int(pid), signal.SIGTERM)
# Check if the process that we killed is alive.
'''
try:
os.kill(int(pid), 0)
raise Exception("""wasn't able to kill the process
HINT:use signal.SIGKILL or signal.SIGABORT""")
except OSError as ex:
continue
'''
print("starting flask")
#subprocess.run(['flask', 'run', '-h', '0.0.0.0', '-p', '10001', '%'], shell=True)
subprocess.run(["flask run -h 0.0.0.0 -p 10001 &"], shell=True, cwd="/home/dheslin/dailybox")
time.sleep(5)
new_flask_app = [p.info for p in psutil.process_iter(attrs=['pid', 'name']) if 'flask' in p.info['name']]
print("new flask app running with pid {}".format(new_flask_app))