@@ -384,7 +384,9 @@ def add_callback(self, callback):
384
384
385
385
def _destroy (self , wk ):
386
386
for callback in self ._callbacks :
387
- callback (self )
387
+ try :
388
+ callback (self )
389
+ except ReferenceError : pass
388
390
389
391
def __getstate__ (self ):
390
392
d = self .__dict__ .copy ()
@@ -508,18 +510,19 @@ def connect(self, s, func):
508
510
if proxy in self ._func_cid_map [s ]:
509
511
return self ._func_cid_map [s ][proxy ]
510
512
511
- proxy .add_callback (self .remove_proxy ) # Remove the proxy when it dies.
513
+ proxy .add_callback (self ._remove_proxy ) # Remove the proxy when it dies.
512
514
self ._cid += 1
513
515
cid = self ._cid
514
516
self ._func_cid_map [s ][proxy ] = cid
515
517
self .callbacks .setdefault (s , dict ())
516
518
self .callbacks [s ][cid ] = proxy
517
519
return cid
518
520
519
- def remove_proxy (self , proxy ):
521
+ def _remove_proxy (self , proxy ):
520
522
for category , proxies in list (six .iteritems (self ._func_cid_map )):
521
- if proxy in proxies :
523
+ try :
522
524
del self .callbacks [category ][proxies [proxy ]]
525
+ except KeyError : pass
523
526
524
527
def disconnect (self , cid ):
525
528
"""
@@ -545,7 +548,10 @@ def process(self, s, *args, **kwargs):
545
548
"""
546
549
if s in self .callbacks :
547
550
for cid , proxy in list (six .iteritems (self .callbacks [s ])):
548
- proxy (* args , ** kwargs )
551
+ try :
552
+ proxy (* args , ** kwargs )
553
+ except ReferenceError :
554
+ self ._remove_proxy (proxy )
549
555
550
556
551
557
class Scheduler (threading .Thread ):
0 commit comments