monkey patch django. close #293 .

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.
This commit is contained in:
benoitc 2012-02-21 14:24:55 +01:00
parent b2c83b2bc3
commit 161c8c03cb
5 changed files with 7 additions and 5 deletions

View File

@ -29,6 +29,7 @@ except ImportError:
from gunicorn import util
def make_wsgi_application():
# validate models
s = StringIO()

View File

@ -7,7 +7,6 @@ from optparse import make_option
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
@ -67,7 +66,5 @@ class Command(BaseCommand):
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()

View File

@ -61,7 +61,7 @@ class AsyncWorker(base.Worker):
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:

View File

@ -14,6 +14,7 @@ except ImportError:
from eventlet import hubs
from eventlet.greenio import GreenSocket
from gunicorn.monkey import patch_django
from gunicorn.workers.async import AsyncWorker
class EventletWorker(AsyncWorker):
@ -23,6 +24,7 @@ class EventletWorker(AsyncWorker):
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):

View File

@ -22,6 +22,7 @@ from gevent.server import StreamServer
from gevent import pywsgi
import gunicorn
from gunicorn.monkey import patch_django
from gunicorn.workers.async import AsyncWorker
from gunicorn.workers.base import Worker
@ -46,6 +47,7 @@ class GeventWorker(AsyncWorker):
def setup(cls):
from gevent import monkey
monkey.noisy = False
patch_django()
monkey.patch_all()
@ -58,7 +60,7 @@ class GeventWorker(AsyncWorker):
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)