-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
69 lines (56 loc) · 2.34 KB
/
main.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
62
63
64
65
66
67
68
69
from gevent import monkey
monkey.patch_all()
import logging
import os
from logging.handlers import RotatingFileHandler
from flask import make_response, request
from gevent.pywsgi import WSGIServer
from app import app
from config.constants import *
from httpServer import run_http_server
def init_logger():
logger = logging.getLogger('app')
logger.setLevel(logging.DEBUG)
fh = RotatingFileHandler(LOG_FILE_PATH, maxBytes=2e7, backupCount=5)
fh_formatter = logging.Formatter('%(asctime)s - %(name)s - %(message)s')
fh.setFormatter(fh_formatter)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch_formatter = logging.Formatter('%(name)s - %(message)s')
# ch_formatter = logging.Formatter('%(filename)s - %(funcName)s - %(process)d - %(thread)d - %(message)s')
ch.setFormatter(ch_formatter)
logger.addHandler(ch)
return logger
if not os.path.isdir(LIVE_TMP_PATH):
os.mkdir(LIVE_TMP_PATH)
@app.after_request
def after(resp):
resp = make_response(resp)
resp.headers['Access-Control-Allow-Origin'] = request.headers.get(
'Origin') or 'http://127.0.0.1:1024'
resp.headers['Access-Control-Allow-Methods'] = 'GET,POST,OPTIONS'
resp.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
# resp.headers['Access-Control-Allow-Credentials'] = 'true'
return resp
if __name__ == "app":
logger = init_logger()
logger.info("========================= Program Started =========================")
run_http_server(DATASET_ROOT_DIR, DATASET_SERVER_PORT)
run_http_server(LIVE_TMP_PATH, LIVE_DEMO_PORT)
if __name__ == "__main__":
logger = init_logger()
logger.info("========================= Program Started =========================")
try:
run_http_server(DATASET_ROOT_DIR, DATASET_SERVER_PORT)
run_http_server(LIVE_TMP_PATH, LIVE_DEMO_PORT)
logger.info(f"Starting WSGI Server on port {SERVER_PORT}...")
web_server = WSGIServer(('0.0.0.0', SERVER_PORT), app)
web_server.serve_forever()
# app.run(host='0.0.0.0', port=8000)
except KeyboardInterrupt:
logger.info("Stopping WSGI Server...")
web_server.stop()
logger.info("WSGI Server stopped.")
logger.info("========================= Program Stopped =========================")