-
-
Save fission6/4506150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gunicorn.conf.py: getting gevent and gevent-psycopg2 running | |
bind = '127.0.0.1:1437' | |
accesslog = "<some-path>/logs/gunicorn-access.log" | |
errorlog = "<some-path>/logs/gunicorn-error.log" | |
workers = 5 | |
try: | |
# fail 'successfully' if either of these modules aren't installed | |
from gevent import monkey | |
import gevent_psycopg2 | |
# setting this inside the 'try' ensures that we only | |
# activate the gevent worker pool if we have gevent installed | |
worker_class = 'gevent' | |
# this ensures forked processes are patched with gevent/gevent-psycopg2 | |
def do_post_fork(server, worker): | |
monkey.patch_all() | |
gevent_psycopg2.monkey_patch() | |
# you should see this text in your gunicorn logs if it was successful | |
worker.log.info("Made Psycopg2 Green") | |
post_fork = do_post_fork | |
except ImportError: | |
pass | |
# in your settings.py, along with the rest of your settings for celery: | |
CELERYD_POOL = 'gevent' | |
# if you want gevent and gevent-pscopg2 to work for management commands, runserver | |
# and other things on the command line, add the following to the top of your manage.py | |
# like so (based on a 1.4.x Django installation): | |
try: | |
from gevent import monkey | |
monkey.patch_all() | |
except ImportError: | |
pass | |
try: | |
import gevent_psycopg2 | |
gevent_psycopg2.monkey_patch() | |
except ImportError: | |
pass | |
# ... the rest of manage.py is here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment