-
Notifications
You must be signed in to change notification settings - Fork 16
/
run.py
122 lines (88 loc) · 2.57 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3
import settings
if __name__ == "__main__":
import logSetup
logSetup.initLogging()
# Shut up fucking annoying psycopg2 vomit every exec.
import warnings
from sqlalchemy import exc as sa_exc
warnings.filterwarnings("ignore", category=UserWarning, module='psycopg2')
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
from app import app
import threading
import time
import calendar
import flags
def thread_run():
interface = None
while flags.RUNSTATE:
try:
if not interface:
interface = FeedFeeder.FeedFeeder.FeedFeeder()
interface.process()
except Exception:
print("Attempting to reconnect. Please stand by.")
interface = None
time.sleep(10)
time.sleep(1)
def startBackgroundThread():
print("ThreadStarter")
bk_thread = threading.Thread(target = thread_run)
bk_thread.start()
return bk_thread
def go():
flags.IS_FLASK = True
settings.MAX_DB_SESSIONS = 10
import sys
if not "debug" in sys.argv:
print("Starting background thread")
# bk_thread = startBackgroundThread()
if "debug" in sys.argv:
print("Running in debug mode.")
app.run(host='0.0.0.0', port=5001, debug=True)
else:
print("Running in normal mode.")
# app.run(host='0.0.0.0', port=5001, processes=10)
# app.run(host='0.0.0.0', port=5001, threaded=True)
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
server.socket_host = "0.0.0.0"
server.socket_port = 5001
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!")
# if not "debug" in sys.argv:
# print("Joining on background thread")
# flags.RUNSTATE = False
# bk_thread.join()
# print("Thread halted. App exiting.")
if __name__ == "__main__":
started = False
if not started:
started = True
go()