-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.py
41 lines (32 loc) · 1.05 KB
/
launch.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
from gunicorn.app.wsgiapp import WSGIApplication
class StandaloneApplication(WSGIApplication):
"""
A class that allows for running a Flask application with Gunicorn.
(https://stackoverflow.com/a/73895674)
=> gunicorn -b 0.0.0.0:80 application:app
:param app_uri: The URI of the Flask application.
:param options: The options to pass to Gunicorn.
"""
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 run() -> None:
"""
A function that runs the Flask application with Gunicorn.
"""
options = {
"bind": "0.0.0.0:80",
"workers": 4,
"timeout": 1000,
}
StandaloneApplication("website.main:app", options).run()
run()