@@ -734,6 +734,24 @@ def _heartbeat_thread(
734734 break
735735 sleep (1 )
736736
737+ def heartbeat_thread (
738+ process , # type: Union[subprocess.Popen[str], subprocess.Popen]
739+ heartbeat , # type: int
740+ ):
741+ """
742+ Just a shorthand to run the heartbeat thread
743+ """
744+ if heartbeat :
745+ heartbeat_thread = threading .Thread (
746+ target = _heartbeat_thread ,
747+ args = (
748+ process ,
749+ heartbeat ,
750+ ),
751+ )
752+ heartbeat_thread .daemon = True
753+ heartbeat_thread .start ()
754+
737755 def _poll_process (
738756 process , # type: Union[subprocess.Popen[str], subprocess.Popen]
739757 timeout , # type: int
@@ -771,16 +789,8 @@ def __check_timeout(
771789 raise StopOnInterrupt (_get_error_output (output_stdout , output_stderr ))
772790
773791 begin_time = datetime .now ()
774- if heartbeat :
775- heartbeat_thread = threading .Thread (
776- target = _heartbeat_thread ,
777- args = (
778- process ,
779- heartbeat ,
780- ),
781- )
782- heartbeat_thread .daemon = True
783- heartbeat_thread .start ()
792+
793+ heartbeat_thread (heartbeat , process )
784794
785795 if encoding is False :
786796 output_stdout = output_stderr = b""
@@ -919,16 +929,8 @@ def _monitor_process(
919929 )
920930 thread .daemon = True # was setDaemon(True) which has been deprecated
921931 thread .start ()
922- if heartbeat :
923- heartbeat_thread = threading .Thread (
924- target = _heartbeat_thread ,
925- args = (
926- process ,
927- heartbeat ,
928- ),
929- )
930- heartbeat_thread .daemon = True
931- heartbeat_thread .start ()
932+
933+ heartbeat_thread (heartbeat , process )
932934
933935 if encoding is False :
934936 output_stdout = output_stderr = b""
0 commit comments