@@ -197,7 +197,7 @@ def __getstate__(self):
197
197
def __setstate__ (self , state ):
198
198
vars (self ).update (state )
199
199
self .callbacks = {
200
- s : {cid : _weak_or_strong_ref (func , self ._remove_proxy )
200
+ s : {cid : _weak_or_strong_ref (func , functools . partial ( self ._remove_proxy , s ) )
201
201
for cid , func in d .items ()}
202
202
for s , d in self .callbacks .items ()}
203
203
self ._func_cid_map = {
@@ -209,7 +209,7 @@ def connect(self, signal, func):
209
209
if self ._signals is not None :
210
210
_api .check_in_list (self ._signals , signal = signal )
211
211
self ._func_cid_map .setdefault (signal , {})
212
- proxy = _weak_or_strong_ref (func , self ._remove_proxy )
212
+ proxy = _weak_or_strong_ref (func , functools . partial ( self ._remove_proxy , signal ) )
213
213
if proxy in self ._func_cid_map [signal ]:
214
214
return self ._func_cid_map [signal ][proxy ]
215
215
cid = next (self ._cid_gen )
@@ -230,18 +230,15 @@ def _connect_picklable(self, signal, func):
230
230
231
231
# Keep a reference to sys.is_finalizing, as sys may have been cleared out
232
232
# at that point.
233
- def _remove_proxy (self , proxy , * , _is_finalizing = sys .is_finalizing ):
233
+ def _remove_proxy (self , signal , proxy , * , _is_finalizing = sys .is_finalizing ):
234
234
if _is_finalizing ():
235
235
# Weakrefs can't be properly torn down at that point anymore.
236
236
return
237
- for signal , proxy_to_cid in list (self ._func_cid_map .items ()):
238
- cid = proxy_to_cid .pop (proxy , None )
239
- if cid is not None :
240
- del self .callbacks [signal ][cid ]
241
- self ._pickled_cids .discard (cid )
242
- break
243
- else :
244
- # Not found
237
+ cid = self ._func_cid_map [signal ].pop (proxy , None )
238
+ if cid is not None :
239
+ del self .callbacks [signal ][cid ]
240
+ self ._pickled_cids .discard (cid )
241
+ else : # Not found
245
242
return
246
243
# Clean up empty dicts
247
244
if len (self .callbacks [signal ]) == 0 :
@@ -260,10 +257,8 @@ def disconnect(self, cid):
260
257
proxy = cid_to_proxy .pop (cid , None )
261
258
if proxy is not None :
262
259
break
263
- else :
264
- # Not found
260
+ else : # Not found
265
261
return
266
-
267
262
proxy_to_cid = self ._func_cid_map [signal ]
268
263
for current_proxy , current_cid in list (proxy_to_cid .items ()):
269
264
if current_cid == cid :
0 commit comments