Skip to content

Commit

Permalink
Use killed status when the stop action is used
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Jul 16, 2024
1 parent dec813e commit eab69ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runusb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit eab69ff

Please sign in to comment.