Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (32 sloc) 1.198 kb
A monkeypatch for ``django.dispatch`` to send signals safely.
>>> import safe_signals
>>> safe_signals.start_the_machine()
``django.dispatch.Signal.send`` is replaced with a safer function that catches
and logs errors. It's like ``Signal.send_robust`` but with logging.
import logging
from django.dispatch.dispatcher import Signal, _make_id
log = logging.getLogger('signals')
def safe_send(self, sender, **named):
responses = []
if not self.receivers:
return responses
# Call each receiver with whatever arguments it can accept.
# Return a list of tuple pairs [(receiver, response), ... ].
for receiver in self._live_receivers(_make_id(sender)):
response = receiver(signal=self, sender=sender, **named)
except Exception, err:
log.error('Error calling signal', exc_info=True)
responses.append((receiver, err))
responses.append((receiver, response))
return responses
safe_send.__doc__ = Signal.send_robust.__doc__
unsafe_send = Signal.send
def start_the_machine():
# Monkeypatch!
Signal.send = safe_send
Signal.send_robust = safe_send
Jump to Line
Something went wrong with that request. Please try again.