Ticket #16547: signal.patch
File signal.patch, 2.8 KB (added by , 13 years ago) |
---|
-
dispatch/dispatcher.py
33 33 self.providing_args = set(providing_args) 34 34 self.lock = threading.Lock() 35 35 36 def connect(self, receiver, sender=None, weak=True, dispatch_uid=None ):36 def connect(self, receiver, sender=None, weak=True, dispatch_uid=None, weight=0): 37 37 """ 38 38 Connect receiver to sender for signal. 39 39 … … 67 67 An identifier used to uniquely identify a particular instance of 68 68 a receiver. This will usually be a string, though it may be 69 69 anything hashable. 70 71 weight 72 Signal priority. Greater run first. 70 73 """ 71 74 from django.conf import settings 72 75 … … 101 104 102 105 self.lock.acquire() 103 106 try: 104 for r_key, _ in self.receivers:107 for r_key, _, w in self.receivers: 105 108 if r_key == lookup_key: 106 109 break 107 110 else: 108 self.receivers.append((lookup_key, receiver ))111 self.receivers.append((lookup_key, receiver, weight)) 109 112 finally: 110 113 self.lock.release() 111 114 … … 139 142 self.lock.acquire() 140 143 try: 141 144 for index in xrange(len(self.receivers)): 142 (r_key, _ ) = self.receivers[index]145 (r_key, _, weight) = self.receivers[index] 143 146 if r_key == lookup_key: 144 147 del self.receivers[index] 145 148 break … … 221 224 none_senderkey = _make_id(None) 222 225 receivers = [] 223 226 224 for (receiverkey, r_senderkey), receiver in self.receivers:227 for (receiverkey, r_senderkey), receiver, weight in sorted(self.receivers, key=lambda x: x[2], reverse=True): 225 228 if r_senderkey == none_senderkey or r_senderkey == senderkey: 226 229 if isinstance(receiver, WEAKREF_TYPES): 227 230 # Dereference the weak reference. … … 240 243 self.lock.acquire() 241 244 try: 242 245 to_remove = [] 243 for key, connected_receiver in self.receivers:246 for key, connected_receiver, weight in self.receivers: 244 247 if connected_receiver == receiver: 245 248 to_remove.append(key) 246 249 for key in to_remove: 247 250 last_idx = len(self.receivers) - 1 248 251 # enumerate in reverse order so that indexes are valid even 249 252 # after we delete some items 250 for idx, (r_key, _ ) in enumerate(reversed(self.receivers)):253 for idx, (r_key, _, weight) in enumerate(reversed(self.receivers)): 251 254 if r_key == key: 252 255 del self.receivers[last_idx-idx] 253 256 finally: