From eab69ff2f04ff0fca357f1ee9efa735d4b3c390d Mon Sep 17 00:00:00 2001 From: WillB97 Date: Tue, 16 Jul 2024 22:04:35 +0100 Subject: [PATCH] Use killed status when the stop action is used --- runusb/__main__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runusb/__main__.py b/runusb/__main__.py index 2374553..3166220 100755 --- a/runusb/__main__.py +++ b/runusb/__main__.py @@ -199,6 +199,7 @@ def mqtt_on_stop_action(client, userdata, message): if MQTT_SETTINGS.active_usercode is not None: # Run the cleanup function to stop the usercode but allow it to be # restarted without reinserting the USB + MQTT_SETTINGS.active_usercode.killed = True MQTT_SETTINGS.active_usercode.cleanup() @@ -331,6 +332,7 @@ def start(self) -> None: run_uuid = uuid.uuid4().hex MQTT_SETTINGS.extra_data["run_uuid"] = run_uuid self.env["run_uuid"] = run_uuid + self.killed = False self.process = subprocess.Popen( [sys.executable, '-u', ROBOT_FILE], stdin=subprocess.DEVNULL, @@ -382,7 +384,10 @@ def _send_signal(self, sig: int) -> None: def _watch_process(self) -> None: # Wait for the process to complete self.process.wait() - if self.process.returncode != 0: + if self.killed: + USERCODE_LOGGER.warning("Your code was stopped.") + LED_CONTROLLER.set_status(LedStatus.Killed) + elif self.process.returncode != 0: USERCODE_LOGGER.warning(f"Process exited with code {self.process.returncode}") LED_CONTROLLER.set_status(LedStatus.Crashed) else: