forked from hypothesis/h
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gunicorn.conf.py
48 lines (38 loc) · 1.71 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
# -*- coding: utf-8 -*-
import os
import socket
if 'GUNICORN_TIMEOUT' in os.environ:
timeout = int(os.environ['GUNICORN_TIMEOUT'])
# Smart detect heroku stack and assume a trusted proxy.
# This is a convenience that should hopefully not be too surprising.
if 'heroku' in os.environ.get('LD_LIBRARY_PATH', ''):
forwarded_allow_ips = '*'
if not os.environ.get('GUNICORN_STATS_DISABLE', None):
if 'STATSD_PORT_8125_UDP_ADDR' in os.environ and \
'STATSD_PORT_8125_UDP_PORT' in os.environ:
_host = os.environ['STATSD_PORT_8125_UDP_ADDR']
_port = os.environ['STATSD_PORT_8125_UDP_PORT']
statsd_host = '{}:{}'.format(_host, _port)
elif 'STATSD_HOST' in os.environ:
_host = os.environ['STATSD_HOST']
_port = os.environ.get('STATSD_PORT', '8125')
statsd_host = '{}:{}'.format(_host, _port)
if 'STATSD_PREFIX' in os.environ:
statsd_prefix = os.environ['STATSD_PREFIX']
def post_fork(server, worker):
# Support back-ported SSL changes on Debian / Ubuntu
import _ssl
import gevent.hub
if hasattr(_ssl, 'SSLContext') and not hasattr(_ssl, '_sslwrap'):
gevent.hub.PYGTE279 = True
# Patch psycopg2 if we're asked to by the worker class
if getattr(server.worker_class, 'use_psycogreen', False):
import psycogreen.gevent
psycogreen.gevent.patch_psycopg()
worker.log.info("Made psycopg green")
def when_ready(server):
name = server.proc_name
if name == 'web' and 'WEB_NUM_WORKERS' in os.environ:
server.num_workers = int(os.environ['WEB_NUM_WORKERS'])
elif name == 'websocket' and 'WEBSOCKET_NUM_WORKERS' in os.environ:
server.num_workers = int(os.environ['WEBSOCKET_NUM_WORKERS'])