From 636d8e0faa99036eac770b72f5808b979f509361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 23 Feb 2017 16:50:04 +0100 Subject: [PATCH] Eventhandling: Wait for command to finish before triggering next Should solve #733 --- src/octoprint/events.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/octoprint/events.py b/src/octoprint/events.py index a117c844..eb500a01 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -332,24 +332,31 @@ class CommandTrigger(GenericEventListener): self._executeGcodeCommand(command, debug=debug) def _executeSystemCommand(self, command, debug=False): - def commandExecutioner(command): + def commandExecutioner(cmd): if debug: - self._logger.info("Executing system command: %s" % command) + self._logger.info("Executing system command: {}".format(cmd)) + else: + self._logger.info("Executing a system command") # we run this with shell=True since we have to trust whatever # our admin configured as command and since we want to allow # shell-alike handling here... - subprocess.Popen(command, shell=True) + subprocess.check_call(cmd, shell=True) - try: - if isinstance(command, (list, tuple, set)): - for c in command: - commandExecutioner(c) - else: - commandExecutioner(command) - except subprocess.CalledProcessError as e: - self._logger.warn("Command failed with return code %i: %s" % (e.returncode, str(e))) - except: - self._logger.exception("Command failed") + def process(): + try: + if isinstance(command, (list, tuple, set)): + for c in command: + commandExecutioner(c) + else: + commandExecutioner(command) + except subprocess.CalledProcessError as e: + self._logger.warn("Command failed with return code %i: %s" % (e.returncode, str(e))) + except: + self._logger.exception("Command failed") + + t = threading.Thread(target=process) + t.daemon = True + t.start() def _executeGcodeCommand(self, command, debug=False): commands = [command]