Skip to content

Commit

Permalink
monkey patch django. close #293 .
Browse files Browse the repository at this point in the history
This patch make sure that we use real threads to get the ident which is
going to happen if we are using gevent or eventlet.
  • Loading branch information
benoitc committed Feb 21, 2012
1 parent b2c83b2 commit 161c8c0
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions gunicorn/app/django_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from gunicorn import util


def make_wsgi_application():
# validate models
s = StringIO()
Expand Down
3 changes: 0 additions & 3 deletions gunicorn/management/commands/run_gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys

from django.core.management.base import BaseCommand, CommandError
from django.conf import settings

from gunicorn.app.djangoapp import DjangoApplicationCommand
from gunicorn.config import make_settings
Expand Down Expand Up @@ -67,7 +66,5 @@ def handle(self, addrport=None, *args, **options):
if addrport:
options['bind'] = addrport

options['default_proc_name'] = settings.SETTINGS_MODULE

admin_media_path = options.pop('admin_media_path', '')
DjangoApplicationCommand(options, admin_media_path).run()
2 changes: 1 addition & 1 deletion gunicorn/workers/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def handle_request(self, req, sock, addr):
self.log.info("Autorestarting worker after current request.")
resp.force_close()
self.alive = False
respiter = self.wsgi(environ, resp.start_response)
respiter = self.app.wsgi()(environ, resp.start_response)
if respiter == ALREADY_HANDLED:
return False
try:
Expand Down
2 changes: 2 additions & 0 deletions gunicorn/workers/geventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from eventlet import hubs
from eventlet.greenio import GreenSocket

from gunicorn.monkey import patch_django
from gunicorn.workers.async import AsyncWorker

class EventletWorker(AsyncWorker):
Expand All @@ -23,6 +24,7 @@ def setup(cls):
import eventlet
if eventlet.version_info < (0,9,7):
raise RuntimeError("You need eventlet >= 0.9.7")
patch_django()
eventlet.monkey_patch(os=False)

def init_process(self):
Expand Down
4 changes: 3 additions & 1 deletion gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from gevent import pywsgi

import gunicorn
from gunicorn.monkey import patch_django
from gunicorn.workers.async import AsyncWorker
from gunicorn.workers.base import Worker

Expand All @@ -46,6 +47,7 @@ class GeventWorker(AsyncWorker):
def setup(cls):
from gevent import monkey
monkey.noisy = False
patch_django()
monkey.patch_all()


Expand All @@ -58,7 +60,7 @@ def run(self):
pool = Pool(self.worker_connections)
if self.server_class is not None:
server = self.server_class(
self.socket, application=self.wsgi, spawn=pool, log=self.log,
self.socket, application=self.app.wsgi, spawn=pool, log=self.log,
handler_class=self.wsgi_handler)
else:
server = StreamServer(self.socket, handle=self.handle, spawn=pool)
Expand Down

0 comments on commit 161c8c0

Please sign in to comment.