Skip to content

Commit 35071df

Browse files
committed
Merge branch 'v1.0.x-maint' of github.com:matplotlib/matplotlib
Conflicts: CHANGELOG doc/users/installing.rst
2 parents a85aca9 + be8521f commit 35071df

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/matplotlib/cbook.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import warnings
99
import numpy as np
1010
import numpy.ma as ma
11-
from weakref import ref
11+
from weakref import ref, WeakKeyDictionary
1212
import cPickle
1313
import os.path
1414
import random
@@ -213,6 +213,7 @@ def __init__(self, signals):
213213
self.signals = set(signals)
214214
self.callbacks = dict([(s, dict()) for s in signals])
215215
self._cid = 0
216+
self._func_cid_map = WeakKeyDictionary()
216217

217218
def _check_signal(self, s):
218219
'make sure *s* is a valid signal or raise a ValueError'
@@ -227,15 +228,12 @@ def connect(self, s, func):
227228
func will be called
228229
"""
229230
self._check_signal(s)
231+
if func in self._func_cid_map:
232+
return self._func_cid_map[func]
230233
proxy = self.BoundMethodProxy(func)
231-
for cid, callback in self.callbacks[s].items():
232-
# Clean out dead references
233-
if callback.inst is not None and callback.inst() is None:
234-
del self.callbacks[s][cid]
235-
elif callback == proxy:
236-
return cid
237234
self._cid += 1
238235
self.callbacks[s][self._cid] = proxy
236+
self._func_cid_map[func] = self._cid
239237
return self._cid
240238

241239
def disconnect(self, cid):

0 commit comments

Comments
 (0)