-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.py
77 lines (54 loc) · 1.5 KB
/
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
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
70
71
72
73
74
75
76
77
#!flask/bin/python
import logSetup
logSetup.initLogging()
from app import app
import threading
import time
def go():
import sys
if "debug" in sys.argv:
from gevent.pywsgi import WSGIServer
print("Running in debug mode.")
app.run(host='0.0.0.0')
else:
import cherrypy
import logging
def fixup_cherrypy_logs():
loggers = logging.Logger.manager.loggerDict.keys()
for name in loggers:
if name.startswith('cherrypy.'):
print("Fixing %s." % name)
logging.getLogger(name).propagate = 0
cherrypy.tree.graft(app, "/")
cherrypy.server.unsubscribe()
# Instantiate a new server object
server = cherrypy._cpserver.Server()
# Configure the server object
if "all" in sys.argv:
server.socket_host = "0.0.0.0"
else:
server.socket_host = "127.0.0.1"
server.socket_port = 5000
server.thread_pool = 8
# For SSL Support
# server.ssl_module = 'pyopenssl'
# server.ssl_certificate = 'ssl/certificate.crt'
# server.ssl_private_key = 'ssl/private.key'
# server.ssl_certificate_chain = 'ssl/bundle.crt'
# Subscribe this server
server.subscribe()
# fixup_cherrypy_logs()
if hasattr(cherrypy.engine, 'signal_handler'):
cherrypy.engine.signal_handler.subscribe()
# Start the server engine (Option 1 *and* 2)
cherrypy.engine.start()
cherrypy.engine.block()
# fixup_cherrypy_logs()
print()
print("Interrupt!")
print("Thread halted. App exiting.")
if __name__ == "__main__":
started = False
if not started:
started = True
go()