parent
c29d6f7676
commit
297c009cf2
|
@ -106,34 +106,31 @@ class Signal(object):
|
|||
assert argspec[2] is not None, \
|
||||
"Signal receivers must accept keyword arguments (**kwargs)."
|
||||
|
||||
receiver_id = _make_id(receiver)
|
||||
if dispatch_uid:
|
||||
lookup_key = (dispatch_uid, _make_id(sender))
|
||||
else:
|
||||
lookup_key = (receiver_id, _make_id(sender))
|
||||
lookup_key = (_make_id(receiver), _make_id(sender))
|
||||
|
||||
if weak:
|
||||
ref = weakref.ref
|
||||
original_receiver = receiver
|
||||
receiver_object = receiver
|
||||
# Check for bound methods
|
||||
if hasattr(receiver, '__self__') and hasattr(receiver, '__func__'):
|
||||
ref = WeakMethod
|
||||
original_receiver = original_receiver.__self__
|
||||
receiver_object = receiver.__self__
|
||||
if sys.version_info >= (3, 4):
|
||||
receiver = ref(receiver)
|
||||
weakref.finalize(original_receiver, self._remove_receiver, receiver_id=receiver_id)
|
||||
weakref.finalize(receiver_object, self._remove_receiver)
|
||||
else:
|
||||
receiver = ref(receiver, self._remove_receiver)
|
||||
# Use the id of the weakref, since that's what passed to the weakref callback!
|
||||
receiver_id = _make_id(receiver)
|
||||
|
||||
with self.lock:
|
||||
self._clear_dead_receivers()
|
||||
for r_key, _, _ in self.receivers:
|
||||
for r_key, _ in self.receivers:
|
||||
if r_key == lookup_key:
|
||||
break
|
||||
else:
|
||||
self.receivers.append((lookup_key, receiver, receiver_id))
|
||||
self.receivers.append((lookup_key, receiver))
|
||||
self.sender_receivers_cache.clear()
|
||||
|
||||
def disconnect(self, receiver=None, sender=None, weak=True, dispatch_uid=None):
|
||||
|
@ -166,7 +163,7 @@ class Signal(object):
|
|||
with self.lock:
|
||||
self._clear_dead_receivers()
|
||||
for index in xrange(len(self.receivers)):
|
||||
(r_key, _, _) = self.receivers[index]
|
||||
(r_key, _) = self.receivers[index]
|
||||
if r_key == lookup_key:
|
||||
del self.receivers[index]
|
||||
break
|
||||
|
@ -270,7 +267,7 @@ class Signal(object):
|
|||
self._clear_dead_receivers()
|
||||
senderkey = _make_id(sender)
|
||||
receivers = []
|
||||
for (receiverkey, r_senderkey), receiver, _ in self.receivers:
|
||||
for (receiverkey, r_senderkey), receiver in self.receivers:
|
||||
if r_senderkey == NONE_ID or r_senderkey == senderkey:
|
||||
receivers.append(receiver)
|
||||
if self.use_caching:
|
||||
|
@ -290,7 +287,7 @@ class Signal(object):
|
|||
non_weak_receivers.append(receiver)
|
||||
return non_weak_receivers
|
||||
|
||||
def _remove_receiver(self, receiver=None, receiver_id=None, _make_id=_make_id):
|
||||
def _remove_receiver(self, receiver=None):
|
||||
# Mark that the self.receivers list has dead weakrefs. If so, we will
|
||||
# clean those up in connect, disconnect and _live_receivers while
|
||||
# holding self.lock. Note that doing the cleanup here isn't a good
|
||||
|
|
Loading…
Reference in New Issue