Ticket #21721: broken_builtins.diff

File broken_builtins.diff, 2.0 KB (added by Florian Apolloner, 11 years ago)
  • django/dispatch/dispatcher.py

    diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
    index d26433a..3993c47 100644
    a b  
    1 import weakref
     1import sys
    22import threading
     3import weakref
     4
    35
    46from django.dispatch import saferef
    57from django.utils.six.moves import xrange
    class Signal(object):  
    105107                assert argspec[2] is not None, \
    106108                    "Signal receivers must accept keyword arguments (**kwargs)."
    107109
     110        receiver_id = _make_id(receiver)
    108111        if dispatch_uid:
    109112            lookup_key = (dispatch_uid, _make_id(sender))
    110113        else:
    111             lookup_key = (_make_id(receiver), _make_id(sender))
     114            lookup_key = (receiver_id, _make_id(sender))
    112115
    113116        if weak:
    114             receiver = saferef.safeRef(receiver, onDelete=self._remove_receiver)
     117            on_delete = self._remove_receiver
     118            if not sys.version_info < (3, 4):
     119                weakref.finalize(receiver, on_delete, receiver_id=receiver_id)
     120                on_delete = None
     121            receiver = saferef.safeRef(receiver, onDelete=on_delete)
    115122
    116123        with self.lock:
    117124            for r_key, _ in self.receivers:
    class Signal(object):  
    262269                non_weak_receivers.append(receiver)
    263270        return non_weak_receivers
    264271
    265     def _remove_receiver(self, receiver):
     272    def _remove_receiver(self, receiver=None, receiver_id=None):
    266273        """
    267274        Remove dead receivers from connections.
    268275        """
    269 
     276        receiver_id = _make_id(receiver) if receiver is not None else receiver_id
    270277        with self.lock:
    271278            to_remove = []
    272279            for key, connected_receiver in self.receivers:
    273                 if connected_receiver == receiver:
     280                if _make_id(connected_receiver) == receiver_id:
    274281                    to_remove.append(key)
    275282            for key in to_remove:
    276283                last_idx = len(self.receivers) - 1
Back to Top