-
Notifications
You must be signed in to change notification settings - Fork 3
/
gunicorn.conf.py
73 lines (50 loc) · 1.75 KB
/
gunicorn.conf.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
###
# app configuration
# https://docs.gunicorn.org/en/stable/settings.html
###
import os
import gunicorn.arbiter
import gunicorn.workers.base
from prometheus_client import multiprocess
from c2cwsgiutils import get_config_defaults, get_logconfig_dict, get_paste_config, prometheus
bind = ":8080"
worker_class = "gthread"
workers = os.environ.get("GUNICORN_WORKERS", 2)
threads = os.environ.get("GUNICORN_THREADS", 10)
paste = get_paste_config()
wsgi_app = paste
accesslog = "-"
access_log_format = os.environ.get(
"GUNICORN_ACCESS_LOG_FORMAT",
'%(H)s %({Host}i)s %(m)s %(U)s?%(q)s "%(f)s" "%(a)s" %(s)s %(B)s %(D)s %(p)s',
)
###
# logging configuration
# https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
###
logconfig_dict = get_logconfig_dict(paste)
if os.environ.get("DEBUG_LOGCONFIG", "0") == "1":
print("LOGCONFIG")
print(logconfig_dict)
raw_paste_global_conf = ["=".join(e) for e in get_config_defaults().items()]
def on_starting(server: gunicorn.arbiter.Arbiter) -> None:
"""
Will start the prometheus server.
Called just before the master process is initialized.
"""
del server
prometheus.start()
def post_fork(server: gunicorn.arbiter.Arbiter, worker: gunicorn.workers.base.Worker) -> None:
"""
Will cleanup the configuration we get from the main process.
Called just after a worker has been forked.
"""
del server, worker
prometheus.cleanup()
def child_exit(server: gunicorn.arbiter.Arbiter, worker: gunicorn.workers.base.Worker) -> None:
"""
Remove the metrics for the exited worker.
Called just after a worker has been exited, in the master process.
"""
del server
multiprocess.mark_process_dead(worker.pid) # type: ignore [no-untyped-call]