-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
61 lines (41 loc) · 1.06 KB
/
server.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
52
53
54
55
56
57
58
59
60
61
import logging
from multiprocessing import Process
from flask import Flask
import config
logging.basicConfig(level=logging.INFO)
log = logging.getLogger("Server")
app = Flask(__name__)
_proc_server = None
_proc_da = None
@app.route('/restart_server/', methods=['GET'])
def restart_server():
global _proc_server
if _proc_server:
_proc_server.terminate()
_proc_server.join()
_proc_server = None
_proc_server = Process(target=_start_server, daemon=True)
_proc_server.start()
return 'ok'
@app.route('/restart_da/', methods=['GET'])
def restart_da():
global _proc_da
if _proc_da:
_proc_da.terminate()
_proc_da.join()
_proc_da = None
_proc_da = Process(target=_start_da, daemon=True)
_proc_da.start()
return 'ok'
def _start_server():
from app import main as server
server()
def _start_da():
from da.DAI import main as da
da()
def main():
app.run('localhost', port=config.RESTART_SERVER_PORT)
if __name__ == '__main__':
restart_server()
restart_da()
main()