Ticket #4909: wsgi-thread-safe-init.patch

File wsgi-thread-safe-init.patch, 1.1 KB (added by colin@…, 17 years ago)
  • django/core/handlers/wsgi.py

     
    66from django import http
    77from pprint import pformat
    88from shutil import copyfileobj
     9from threading import Lock
    910try:
    1011    from cStringIO import StringIO
    1112except ImportError:
     
    176177    raw_post_data = property(_get_raw_post_data)
    177178
    178179class WSGIHandler(BaseHandler):
     180    initLock = Lock()
    179181    def __call__(self, environ, start_response):
    180182        from django.conf import settings
    181183
    182184        # Set up middleware if needed. We couldn't do this earlier, because
    183185        # settings weren't available.
    184186        if self._request_middleware is None:
    185             self.load_middleware()
     187            self.initLock.acquire()
     188            # Check that we are the first thread to try loading the middleware.
     189            if self._request_middleware is None:
     190                self.load_middleware()
     191            self.initLock.release()
    186192
    187193        dispatcher.send(signal=signals.request_started)
    188194        try:
Back to Top