@@ -119,8 +119,6 @@ def execute(self, handle_errors: bool = True) -> subprocess.CompletedProcess[Any
119119 time .sleep (0.01 )
120120 # TIMEOUT CHECK
121121 if self .timeout is not None and (time .monotonic () - start_time ) > self .timeout :
122- self .logger .error (f"Process timed out after { self .timeout } seconds. Terminating process tree (PID={ process .pid } )." )
123- self ._terminate_process_tree (process .pid )
124122 raise subprocess .TimeoutExpired (
125123 cmd = self .command_str ,
126124 timeout = self .timeout ,
@@ -130,20 +128,10 @@ def execute(self, handle_errors: bool = True) -> subprocess.CompletedProcess[Any
130128 process .wait ()
131129 # NON-STREAMING MODE (communicate with native timeout)
132130 elif self .capture_output and not self .print_output :
133- try :
134- stdout , stderr = process .communicate (timeout = self .timeout )
135- except subprocess .TimeoutExpired :
136- self .logger .error (f"Process timed out after { self .timeout } seconds. Terminating process tree (PID={ process .pid } )." )
137- self ._terminate_process_tree (process .pid )
138- raise
131+ stdout , stderr = process .communicate (timeout = self .timeout )
139132 else :
140133 # No output capturing; just wait for completion or timeout
141- try :
142- process .wait (timeout = self .timeout )
143- except subprocess .TimeoutExpired :
144- self .logger .error (f"Process timed out after { self .timeout } seconds. Terminating process tree (PID={ process .pid } )." )
145- self ._terminate_process_tree (process .pid )
146- raise
134+ process .wait (timeout = self .timeout )
147135 # HANDLE RETURN CODES AND ERROR INTERPRETATION
148136 if handle_errors :
149137 # Check return code
@@ -152,6 +140,7 @@ def execute(self, handle_errors: bool = True) -> subprocess.CompletedProcess[Any
152140 else :
153141 completed_process = subprocess .CompletedProcess (process .args , process .returncode , stdout , stderr )
154142 except subprocess .TimeoutExpired :
143+ self ._terminate_process_tree (process .pid )
155144 raise UserNotificationException (f"Command '{ self .command_str } ' timed out after { self .timeout } seconds and was forcefully terminated." ) from None
156145 except subprocess .CalledProcessError as e :
157146 raise UserNotificationException (f"Command '{ self .command_str } ' execution failed with return code { e .returncode } " ) from None
0 commit comments