File tree 2 files changed +13
-6
lines changed
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -665,7 +665,7 @@ def __del__(self):
665
665
def reset (self ):
666
666
if self .connection :
667
667
self .connection .disconnect ()
668
- self .connection .clear_connect_callbacks ( )
668
+ self .connection ._deregister_connect_callbacks ( self . on_connect )
669
669
self .connection_pool .release (self .connection )
670
670
self .connection = None
671
671
self .health_check_response_counter = 0
@@ -723,7 +723,7 @@ def execute_command(self, *args):
723
723
)
724
724
# register a callback that re-subscribes to any channels we
725
725
# were listening to when we were disconnected
726
- self .connection .register_connect_callback (self .on_connect )
726
+ self .connection ._register_connect_callback (self .on_connect )
727
727
if self .push_handler_func is not None and not HIREDIS_AVAILABLE :
728
728
self .connection ._parser .set_push_handler (self .push_handler_func )
729
729
connection = self .connection
Original file line number Diff line number Diff line change @@ -237,11 +237,16 @@ def _construct_command_packer(self, packer):
237
237
else :
238
238
return PythonRespSerializer (self ._buffer_cutoff , self .encoder .encode )
239
239
240
- def register_connect_callback (self , callback ):
241
- self ._connect_callbacks .append (weakref .WeakMethod (callback ))
240
+ def _register_connect_callback (self , callback ):
241
+ wm = weakref .WeakMethod (callback )
242
+ if wm not in self ._connect_callbacks :
243
+ self ._connect_callbacks .append (wm )
242
244
243
- def clear_connect_callbacks (self ):
244
- self ._connect_callbacks = []
245
+ def _deregister_connect_callback (self , callback ):
246
+ try :
247
+ self ._connect_callbacks .remove (weakref .WeakMethod (callback ))
248
+ except ValueError :
249
+ pass
245
250
246
251
def set_parser (self , parser_class ):
247
252
"""
@@ -279,6 +284,8 @@ def connect(self):
279
284
280
285
# run any user callbacks. right now the only internal callback
281
286
# is for pubsub channel/pattern resubscription
287
+ # first, remove any dead weakrefs
288
+ self ._connect_callbacks = [ref for ref in self ._connect_callbacks if ref ()]
282
289
for ref in self ._connect_callbacks :
283
290
callback = ref ()
284
291
if callback :
You can’t perform that action at this time.
0 commit comments