@@ -602,8 +602,6 @@ def execute(self, command,
602602 if as_process :
603603 return self .AutoInterrupt (proc , command )
604604
605- kill_check = threading .Event ()
606-
607605 def _kill_process (pid ):
608606 """ Callback method to kill a process. """
609607 p = Popen (['ps' , '--ppid' , str (pid )], stdout = PIPE )
@@ -625,20 +623,24 @@ def _kill_process(pid):
625623 return
626624 # end
627625
628- watchdog = threading .Timer (timeout , _kill_process , args = (proc .pid , ))
626+ if timeout :
627+ kill_check = threading .Event ()
628+ watchdog = threading .Timer (timeout , _kill_process , args = (proc .pid , ))
629629
630630 # Wait for the process to return
631631 status = 0
632632 stdout_value = b''
633633 stderr_value = b''
634634 try :
635635 if output_stream is None :
636- watchdog .start ()
636+ if timeout :
637+ watchdog .start ()
637638 stdout_value , stderr_value = proc .communicate ()
638- watchdog .cancel ()
639- if kill_check .isSet ():
640- stderr_value = 'Timeout: the command "%s" did not complete in %d ' \
641- 'secs.' % (" " .join (command ), timeout )
639+ if timeout :
640+ watchdog .cancel ()
641+ if kill_check .isSet ():
642+ stderr_value = 'Timeout: the command "%s" did not complete in %d ' \
643+ 'secs.' % (" " .join (command ), timeout )
642644 # strip trailing "\n"
643645 if stdout_value .endswith (b"\n " ):
644646 stdout_value = stdout_value [:- 1 ]
0 commit comments