Skip to content

Instantly share code, notes, and snippets.

@fission6
Forked from jaddison/gist:4506070
Created January 10, 2013 21:56
Show Gist options
  • Save fission6/4506150 to your computer and use it in GitHub Desktop.
Save fission6/4506150 to your computer and use it in GitHub Desktop.
# 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