From 407d30df11de75ac8c6b4717ff3fec5a1445d86e Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 25 Nov 2025 07:30:09 -0800 Subject: [PATCH] feat: Do not exit from default Python script When a new App is created, it is populated with a simple Python script and "bare minimum" Arduino sketch. For initial explorations of a new system, or when troubleshooting, it is common to create very simple programs (AKA "Hello, world!"). Although a complex App will typically consist of a Python script and Arduino sketch program working in coordination, for users with prior experience with Arduino the natural approach to creating a minimal App will be to simply write some familiar Arduino sketch code, leaving the default Python script code as-is. The App is considered to be in a "stopped" state as soon as the Python script exits. This is the correct approach, but may be confusing to users due to the fact that, except perhaps under exceptional conditions, the Arduino sketch program runs perpetually. The author of a minimal sketch-based "Hello, world!" App will find it unintuitive if their App goes into a "stopped" state immediately after starting. The previous default Python script produced exactly that result. The default Python script is hereby changed to the more intuitive behavior of running perpetually. Co-authored-by: Davide --- .../app/generator/app_template/python/main.py | 17 +++++++++++++---- .../testdata/app-all.golden/python/main.py | 17 +++++++++++++---- .../app-no-sketch.golden/python/main.py | 17 +++++++++++++---- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/internal/orchestrator/app/generator/app_template/python/main.py b/internal/orchestrator/app/generator/app_template/python/main.py index 9ef98b13..fb56fb23 100644 --- a/internal/orchestrator/app/generator/app_template/python/main.py +++ b/internal/orchestrator/app/generator/app_template/python/main.py @@ -1,6 +1,15 @@ -def main(): - print("Hello World!") +import time +from arduino.app_utils import App -if __name__ == "__main__": - main() +print("Hello world!") + + +def loop(): + """This function is called repeatedly by the App framework.""" + # You can replace this with any code you want your App to run repeatedly. + time.sleep(10) + + +# See: https://docs.arduino.cc/software/app-lab/tutorials/getting-started/#app-run +App.run(user_loop=loop) diff --git a/internal/orchestrator/app/generator/testdata/app-all.golden/python/main.py b/internal/orchestrator/app/generator/testdata/app-all.golden/python/main.py index 9ef98b13..fb56fb23 100644 --- a/internal/orchestrator/app/generator/testdata/app-all.golden/python/main.py +++ b/internal/orchestrator/app/generator/testdata/app-all.golden/python/main.py @@ -1,6 +1,15 @@ -def main(): - print("Hello World!") +import time +from arduino.app_utils import App -if __name__ == "__main__": - main() +print("Hello world!") + + +def loop(): + """This function is called repeatedly by the App framework.""" + # You can replace this with any code you want your App to run repeatedly. + time.sleep(10) + + +# See: https://docs.arduino.cc/software/app-lab/tutorials/getting-started/#app-run +App.run(user_loop=loop) diff --git a/internal/orchestrator/app/generator/testdata/app-no-sketch.golden/python/main.py b/internal/orchestrator/app/generator/testdata/app-no-sketch.golden/python/main.py index 9ef98b13..fb56fb23 100644 --- a/internal/orchestrator/app/generator/testdata/app-no-sketch.golden/python/main.py +++ b/internal/orchestrator/app/generator/testdata/app-no-sketch.golden/python/main.py @@ -1,6 +1,15 @@ -def main(): - print("Hello World!") +import time +from arduino.app_utils import App -if __name__ == "__main__": - main() +print("Hello world!") + + +def loop(): + """This function is called repeatedly by the App framework.""" + # You can replace this with any code you want your App to run repeatedly. + time.sleep(10) + + +# See: https://docs.arduino.cc/software/app-lab/tutorials/getting-started/#app-run +App.run(user_loop=loop)