@@ -857,14 +857,12 @@ def _disable_heartbeat_thread(self):
857
857
self ._heartbeat_thread .disable ()
858
858
859
859
def _close_heartbeat_thread (self , timeout_ms = None ):
860
- with self ._lock :
861
- if self ._heartbeat_thread is not None :
862
- heartbeat_log .info ('Stopping heartbeat thread' )
863
- try :
864
- self ._heartbeat_thread .close (timeout_ms = timeout_ms )
865
- except ReferenceError :
866
- pass
867
- self ._heartbeat_thread = None
860
+ if self ._heartbeat_thread is not None :
861
+ try :
862
+ self ._heartbeat_thread .close (timeout_ms = timeout_ms )
863
+ except ReferenceError :
864
+ pass
865
+ self ._heartbeat_thread = None
868
866
869
867
def __del__ (self ):
870
868
try :
@@ -1047,17 +1045,20 @@ def disable(self):
1047
1045
self .enabled = False
1048
1046
1049
1047
def close (self , timeout_ms = None ):
1050
- if self .closed :
1051
- return
1052
- self . closed = True
1048
+ with self .coordinator . _lock :
1049
+ if self . closed :
1050
+ return
1053
1051
1054
- # Generally this should not happen - close() is triggered
1055
- # by the coordinator. But in some cases GC may close the coordinator
1056
- # from within the heartbeat thread.
1057
- if threading .current_thread () == self :
1058
- return
1052
+ heartbeat_log .info ('Stopping heartbeat thread' )
1053
+ self .closed = True
1059
1054
1060
- with self .coordinator ._lock :
1055
+ # Generally this should not happen - close() is triggered
1056
+ # by the coordinator. But in some cases GC may close the coordinator
1057
+ # from within the heartbeat thread.
1058
+ if threading .current_thread () == self :
1059
+ return
1060
+
1061
+ # Notify coordinator lock to wake thread from sleep/lock.wait
1061
1062
self .coordinator ._lock .notify ()
1062
1063
1063
1064
if self .is_alive ():
0 commit comments