-
Notifications
You must be signed in to change notification settings - Fork 0
/
gunicornserver.py
76 lines (60 loc) · 2.32 KB
/
gunicornserver.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
# encoding=utf-8
from flask_script import Command, Option
from multiprocessing import cpu_count
class GunicornServer(Command):
description = 'Run the app within Gunicorn'
def __init__(self, host='0.0.0.0', port=5000, workers=9, worker_class="sync", daemon=False):
self.port = port
self.host = host
self.workers = workers
self.worker_class = worker_class
self.daemon = daemon
def get_options(self):
return (
Option('-H', '--host',
dest='host',
default=self.host),
Option('-p', '--port',
dest='port',
type=int,
default=self.port),
Option('-w', '--workers',
dest='workers',
type=int,
default=self.workers),
Option("-c", "--worker_class",
dest='worker_class',
type=str,
default=self.worker_class),
Option("-d", "--daemon",
dest="daemon",
type=bool,
default=self.daemon)
)
def __call__(self, app, host, port, workers, worker_class, daemon):
print "......"
# print args
# app, host, port, workers, worker_class, daemon = args
from gunicorn import version_info
if version_info < (0, 9, 0):
from gunicorn.arbiter import Arbiter
from gunicorn.config import Config
arbiter = Arbiter(Config({'bind': "%s:%d" % (host, int(port)),
'workers': workers,
'worker_class': worker_class,
'daemon': daemon}),
app)
arbiter.run()
else:
from gunicorn.app.base import Application
class FlaskApplication(Application):
def init(self, parser, opts, args):
return {
'bind': '{0}:{1}'.format(host, port),
'workers': workers,
'worker_class': worker_class,
'daemon': daemon
}
def load(self):
return app
FlaskApplication().run()