Ticket #14533: signals_ts.patch
File signals_ts.patch, 1.9 KB (added by , 14 years ago) |
---|
-
django/dispatch/dispatcher.py
1 1 import weakref 2 import threading 2 3 3 4 from django.dispatch import saferef 4 5 … … 26 27 providing_args 27 28 A list of the arguments this signal can pass along in a send() call. 28 29 """ 30 self.lock = threading.Lock() 29 31 self.receivers = [] 30 32 if providing_args is None: 31 33 providing_args = [] … … 66 68 a receiver. This will usually be a string, though it may be 67 69 anything hashable. 68 70 """ 71 self.lock.acquire() 69 72 from django.conf import settings 70 73 71 74 # If DEBUG is on, check that we got a good receiver … … 102 105 break 103 106 else: 104 107 self.receivers.append((lookup_key, receiver)) 108 self.lock.release() 105 109 106 110 def disconnect(self, receiver=None, sender=None, weak=True, dispatch_uid=None): 107 111 """ … … 125 129 dispatch_uid 126 130 the unique identifier of the receiver to disconnect 127 131 """ 132 self.lock.acquire() 128 133 if dispatch_uid: 129 134 lookup_key = (dispatch_uid, _make_id(sender)) 130 135 else: … … 135 140 if r_key == lookup_key: 136 141 del self.receivers[index] 137 142 break 143 self.lock.release() 138 144 139 145 def send(self, sender, **named): 140 146 """ … … 226 232 """ 227 233 Remove dead receivers from connections. 228 234 """ 229 235 self.lock.acquire() 230 236 to_remove = [] 231 237 for key, connected_receiver in self.receivers: 232 238 if connected_receiver == receiver: … … 235 241 for idx, (r_key, _) in enumerate(self.receivers): 236 242 if r_key == key: 237 243 del self.receivers[idx] 244 self.lock.release()