Ticket #14533: signals_ts.patch

File signals_ts.patch, 1.9 KB (added by milosu, 14 years ago)
  • django/dispatch/dispatcher.py

     
    11import weakref
     2import threading
    23
    34from django.dispatch import saferef
    45
     
    2627        providing_args
    2728            A list of the arguments this signal can pass along in a send() call.
    2829        """
     30        self.lock = threading.Lock()
    2931        self.receivers = []
    3032        if providing_args is None:
    3133            providing_args = []
     
    6668                a receiver. This will usually be a string, though it may be
    6769                anything hashable.
    6870        """
     71        self.lock.acquire()
    6972        from django.conf import settings
    7073       
    7174        # If DEBUG is on, check that we got a good receiver
     
    102105                break
    103106        else:
    104107            self.receivers.append((lookup_key, receiver))
     108        self.lock.release()
    105109
    106110    def disconnect(self, receiver=None, sender=None, weak=True, dispatch_uid=None):
    107111        """
     
    125129            dispatch_uid
    126130                the unique identifier of the receiver to disconnect
    127131        """
     132        self.lock.acquire()
    128133        if dispatch_uid:
    129134            lookup_key = (dispatch_uid, _make_id(sender))
    130135        else:
     
    135140            if r_key == lookup_key:
    136141                del self.receivers[index]
    137142                break
     143        self.lock.release()
    138144
    139145    def send(self, sender, **named):
    140146        """
     
    226232        """
    227233        Remove dead receivers from connections.
    228234        """
    229 
     235        self.lock.acquire()
    230236        to_remove = []
    231237        for key, connected_receiver in self.receivers:
    232238            if connected_receiver == receiver:
     
    235241            for idx, (r_key, _) in enumerate(self.receivers):
    236242                if r_key == key:
    237243                    del self.receivers[idx]
     244        self.lock.release()
Back to Top