1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Major refactoring of django.dispatch with an eye towards speed. The net result is that signals are up to 90% faster.

Though some attempts and backwards-compatibility were made, speed trumped compatibility. Thus, as usual, check BackwardsIncompatibleChanges for the complete list of backwards-incompatible changes.

Thanks to Jeremy Dunck and Keith Busell for the bulk of the work; some ideas from Brian Herring's previous work (refs #4561) were incorporated.

Documentation is, sigh, still forthcoming.

Fixes #6814 and #3951 (with the new dispatch_uid argument to connect).


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2008-08-06 15:32:46 +00:00
parent d06b474251
commit 34a3bd5225
33 changed files with 380 additions and 848 deletions

View File

@@ -2,7 +2,6 @@ import sys
from django import http
from django.core import signals
from django.dispatch import dispatcher
from django.utils.encoding import force_unicode
class BaseHandler(object):
@@ -122,7 +121,7 @@ class BaseHandler(object):
except: # Handle everything else, including SuspiciousOperation, etc.
# Get the exception info now, in case another exception is thrown later.
exc_info = sys.exc_info()
receivers = dispatcher.send(signal=signals.got_request_exception, request=request)
receivers = signals.got_request_exception.send(sender=self.__class__, request=request)
return self.handle_uncaught_exception(request, resolver, exc_info)
def handle_uncaught_exception(self, request, resolver, exc_info):

View File

@@ -5,7 +5,6 @@ from django import http
from django.core import signals
from django.core.handlers.base import BaseHandler
from django.core.urlresolvers import set_script_prefix
from django.dispatch import dispatcher
from django.utils import datastructures
from django.utils.encoding import force_unicode, smart_str
@@ -174,7 +173,7 @@ class ModPythonHandler(BaseHandler):
self.load_middleware()
set_script_prefix(req.get_options().get('django.root', ''))
dispatcher.send(signal=signals.request_started)
signals.request_started.send(sender=self.__class__)
try:
try:
request = self.request_class(req)
@@ -188,7 +187,7 @@ class ModPythonHandler(BaseHandler):
response = middleware_method(request, response)
response = self.apply_response_fixes(request, response)
finally:
dispatcher.send(signal=signals.request_finished)
signals.request_finished.send(sender=self.__class__)
# Convert our custom HttpResponse object back into the mod_python req.
req.content_type = response['Content-Type']

View File

@@ -9,7 +9,6 @@ from django import http
from django.core import signals
from django.core.handlers import base
from django.core.urlresolvers import set_script_prefix
from django.dispatch import dispatcher
from django.utils import datastructures
from django.utils.encoding import force_unicode
@@ -207,7 +206,7 @@ class WSGIHandler(base.BaseHandler):
self.initLock.release()
set_script_prefix(base.get_script_name(environ))
dispatcher.send(signal=signals.request_started)
signals.request_started.send(sender=self.__class__)
try:
try:
request = self.request_class(environ)
@@ -221,7 +220,7 @@ class WSGIHandler(base.BaseHandler):
response = middleware_method(request, response)
response = self.apply_response_fixes(request, response)
finally:
dispatcher.send(signal=signals.request_finished)
signals.request_finished.send(sender=self.__class__)
try:
status_text = STATUS_CODE_TEXT[response.status_code]

View File

@@ -15,7 +15,6 @@ class Command(NoArgsCommand):
def handle_noargs(self, **options):
from django.conf import settings
from django.db import connection, transaction, models
from django.dispatch import dispatcher
from django.core.management.sql import sql_flush, emit_post_sync_signal
verbosity = int(options.get('verbosity', 1))

View File

@@ -492,6 +492,6 @@ def emit_post_sync_signal(created_models, verbosity, interactive):
app_name = app.__name__.split('.')[-2]
if verbosity >= 2:
print "Running post-sync handlers for application", app_name
dispatcher.send(signal=models.signals.post_syncdb, sender=app,
app=app, created_models=created_models,
verbosity=verbosity, interactive=interactive)
models.signals.post_syncdb.send(sender=app, app=app,
created_models=created_models, verbosity=verbosity,
interactive=interactive)

View File

@@ -1,3 +1,5 @@
request_started = object()
request_finished = object()
got_request_exception = object()
from django.dispatch import Signal
request_started = Signal()
request_finished = Signal()
got_request_exception = Signal(providing_args=["request"])