From c261ee51f30a804f86eec462803f55687f30c9b2 Mon Sep 17 00:00:00 2001 From: Arksine Date: Fri, 1 Jan 2021 20:34:02 -0500 Subject: [PATCH] shell_command: Add retries to "run_with_response" method Signed-off-by: Eric Callahan --- moonraker/plugins/shell_command.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/moonraker/plugins/shell_command.py b/moonraker/plugins/shell_command.py index 9b91f7e..e033baf 100644 --- a/moonraker/plugins/shell_command.py +++ b/moonraker/plugins/shell_command.py @@ -7,7 +7,6 @@ import os import shlex import subprocess import logging -import tornado from tornado import gen from tornado.ioloop import IOLoop @@ -100,7 +99,7 @@ class ShellCommand: logging.info(msg) return success - async def run_with_response(self, timeout=2.): + async def run_with_response(self, timeout=2., retries=1): result = [] def cb(data): @@ -109,7 +108,16 @@ class ShellCommand: result.append(data.decode()) prev_cb = self.output_cb self.output_cb = cb - await self.run(timeout) + while 1: + ret = await self.run(timeout) + if not ret or not result: + retries -= 1 + if not retries: + return None + await gen.sleep(.5) + result.clear() + continue + break self.output_cb = prev_cb return "\n".join(result)