@@ -776,12 +776,12 @@ def _disable_heartbeat_thread(self):
776
776
if self ._heartbeat_thread is not None :
777
777
self ._heartbeat_thread .disable ()
778
778
779
- def _close_heartbeat_thread (self ):
779
+ def _close_heartbeat_thread (self , timeout_ms = None ):
780
780
with self ._lock :
781
781
if self ._heartbeat_thread is not None :
782
782
log .info ('Stopping heartbeat thread' )
783
783
try :
784
- self ._heartbeat_thread .close ()
784
+ self ._heartbeat_thread .close (timeout_ms = timeout_ms )
785
785
except ReferenceError :
786
786
pass
787
787
self ._heartbeat_thread = None
@@ -790,13 +790,13 @@ def __del__(self):
790
790
if hasattr (self , '_heartbeat_thread' ):
791
791
self ._close_heartbeat_thread ()
792
792
793
- def close (self ):
793
+ def close (self , timeout_ms = None ):
794
794
"""Close the coordinator, leave the current group,
795
795
and reset local generation / member_id"""
796
- self ._close_heartbeat_thread ()
797
- self .maybe_leave_group ()
796
+ self ._close_heartbeat_thread (timeout_ms = timeout_ms )
797
+ self .maybe_leave_group (timeout_ms = timeout_ms )
798
798
799
- def maybe_leave_group (self ):
799
+ def maybe_leave_group (self , timeout_ms = None ):
800
800
"""Leave the current group and reset local generation/memberId."""
801
801
with self ._client ._lock , self ._lock :
802
802
if (not self .coordinator_unknown ()
@@ -811,7 +811,7 @@ def maybe_leave_group(self):
811
811
future = self ._client .send (self .coordinator_id , request )
812
812
future .add_callback (self ._handle_leave_group_response )
813
813
future .add_errback (log .error , "LeaveGroup request failed: %s" )
814
- self ._client .poll (future = future )
814
+ self ._client .poll (future = future , timeout_ms = timeout_ms )
815
815
816
816
self .reset_generation ()
817
817
@@ -957,7 +957,7 @@ def disable(self):
957
957
log .debug ('Disabling heartbeat thread' )
958
958
self .enabled = False
959
959
960
- def close (self ):
960
+ def close (self , timeout_ms = None ):
961
961
if self .closed :
962
962
return
963
963
self .closed = True
@@ -972,7 +972,9 @@ def close(self):
972
972
self .coordinator ._lock .notify ()
973
973
974
974
if self .is_alive ():
975
- self .join (self .coordinator .config ['heartbeat_interval_ms' ] / 1000 )
975
+ if timeout_ms is None :
976
+ timeout_ms = self .coordinator .config ['heartbeat_interval_ms' ]
977
+ self .join (timeout_ms / 1000 )
976
978
if self .is_alive ():
977
979
log .warning ("Heartbeat thread did not fully terminate during close" )
978
980
0 commit comments