-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
40 lines (31 loc) · 1.03 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
try:
import os
import sys
import gunicorn
except ImportError:
os.system('pip install -r .requirements.txt')
import gunicorn.app.base
from gunicorn.six import iteritems
import multiprocessing
from wsgi import run
HOST = sys.argv[1]
PORT = sys.argv[2]
class CommentorApp(gunicorn.app.base.BaseApplication):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super(CommentorApp, self).__init__()
def load_config(self):
config = dict([(key, value) for key, value in iteritems(self.options)
if key in self.cfg.settings and value is not None])
for key, value in iteritems(config):
self.cfg.set(key.lower(), value)
def load(self):
return self.application
if __name__ == '__main__':
options = {
'bind': '%s:%s' % (HOST, PORT),
'workers': multiprocessing.cpu_count() * 2 + 1,
'access_log_format': "%(h)s %(q)s %(U)s %(s)s %(b)s"
}
CommentorApp(run, options).run()