-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.py
42 lines (33 loc) · 1.08 KB
/
webserver.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
from multiprocessing import cpu_count
from string import ascii_letters
from random import choice as random_choice
import gunicorn
from gunicorn.app.wsgiapp import WSGIApplication
PORT_WEB = 8080
LISTEN_ADDRESS = '0.0.0.0'
# https://docs.gunicorn.org/en/stable/settings.html
class StandaloneApplication(WSGIApplication):
def __init__(self, app_uri, options=None):
self.options = options or {}
self.app_uri = app_uri
super().__init__()
def load_config(self):
config = {
key: value
for key, value in self.options.items()
if key in self.cfg.settings and value is not None
}
for key, value in config.items():
self.cfg.set(key.lower(), value)
def init_webserver():
gunicorn.SERVER = ''.join(random_choice(ascii_letters) for _ in range(10))
opts = {
'workers': (cpu_count() * 2) + 1,
'bind': f'{LISTEN_ADDRESS}:{PORT_WEB}',
'reload': True,
'loglevel': 'info',
}
StandaloneApplication(
app_uri="app.main:app",
options=opts
).run()