From e15ef345bc40fc719732b7ae61f380d2bcb1ceb0 Mon Sep 17 00:00:00 2001 From: Arksine Date: Fri, 21 May 2021 07:19:29 -0400 Subject: [PATCH] shell_command: run_with_response fixes Reset the command tracking data before each retry. If the command is cancelled by the user immediately break. Signed-off-by: Eric Callahan --- moonraker/components/shell_command.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/moonraker/components/shell_command.py b/moonraker/components/shell_command.py index b096827..c22e498 100644 --- a/moonraker/components/shell_command.py +++ b/moonraker/components/shell_command.py @@ -192,9 +192,10 @@ class ShellCommand: log_complete: bool = True, sig_idx: int = 1 ) -> str: - self._reset_command_data() retries = max(1, retries) while retries > 0: + self._reset_command_data() + timed_out = False stdout = stderr = b"" if await self._create_subprocess(): assert self.proc is not None @@ -204,6 +205,7 @@ class ShellCommand: ret, timeout=timeout) except asyncio.TimeoutError: complete = False + timed_out = True await self.proc.cancel(sig_idx) else: complete = not self.cancelled @@ -211,10 +213,12 @@ class ShellCommand: logging.info(f"{self.command[0]}: {stderr.decode()}") if self._check_proc_success(complete, log_complete): return stdout.decode().rstrip("\n") - elif stdout: + if stdout: logging.debug( f"Shell command '{self.name}' output:" f"\n{stdout.decode()}") + if self.cancelled and not timed_out: + break retries -= 1 await gen.sleep(.5) raise ShellCommandError(