File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -690,7 +690,7 @@ def __del__(self):
690690    def  reset (self ):
691691        if  self .connection :
692692            self .connection .disconnect ()
693-             self .connection .clear_connect_callbacks ( )
693+             self .connection ._deregister_connect_callback ( self . on_connect )
694694            self .connection_pool .release (self .connection )
695695            self .connection  =  None 
696696        self .health_check_response_counter  =  0 
@@ -748,7 +748,7 @@ def execute_command(self, *args):
748748            )
749749            # register a callback that re-subscribes to any channels we 
750750            # were listening to when we were disconnected 
751-             self .connection .register_connect_callback (self .on_connect )
751+             self .connection ._register_connect_callback (self .on_connect )
752752            if  self .push_handler_func  is  not   None  and  not  HIREDIS_AVAILABLE :
753753                self .connection ._parser .set_push_handler (self .push_handler_func )
754754        connection  =  self .connection 
Original file line number Diff line number Diff line change @@ -1771,7 +1771,7 @@ def execute_command(self, *args):
17711771            )
17721772            # register a callback that re-subscribes to any channels we 
17731773            # were listening to when we were disconnected 
1774-             self .connection .register_connect_callback (self .on_connect )
1774+             self .connection ._register_connect_callback (self .on_connect )
17751775            if  self .push_handler_func  is  not   None  and  not  HIREDIS_AVAILABLE :
17761776                self .connection ._parser .set_push_handler (self .push_handler_func )
17771777        connection  =  self .connection 
Original file line number Diff line number Diff line change @@ -237,11 +237,16 @@ def _construct_command_packer(self, packer):
237237        else :
238238            return  PythonRespSerializer (self ._buffer_cutoff , self .encoder .encode )
239239
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 )
242244
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 
245250
246251    def  set_parser (self , parser_class ):
247252        """ 
@@ -279,6 +284,8 @@ def connect(self):
279284
280285        # run any user callbacks. right now the only internal callback 
281286        # 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 ()]
282289        for  ref  in  self ._connect_callbacks :
283290            callback  =  ref ()
284291            if  callback :
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments