From ce40450229e2235a8652a59b1cd58ab979038b28 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sat, 19 Apr 2025 23:22:30 +0200 Subject: [PATCH] We know when it stops now --- appstore.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/appstore.py b/appstore.py index dbf9c467..13690489 100644 --- a/appstore.py +++ b/appstore.py @@ -411,14 +411,12 @@ create_drawer() # uasyncio isn't available on web - import lvgl as lv import uasyncio as asyncio import utime import gc import _thread - # Function to execute the child script as a coroutine async def execute_script(script_source, lvgl_obj): try: @@ -488,22 +486,27 @@ async def app_main(): async def main(): print("Main: Starting child script") task = asyncio.create_task(execute_script(script_buffer, subwindow)) - while True: + while not task.done(): await asyncio.sleep_ms(100) + print("Main stopped") + # Function to run the event loop in a background thread -def run_event_loop(): +def run_app(): try: asyncio.run(main()) + print("Event loop stopped") + subwindow.delete() except Exception as e: print("Event loop error:", e) + # Start the event loop in a background thread gc.collect() print("Free memory before loop:", gc.mem_free()) try: _thread.stack_size(8192) - _thread.start_new_thread(run_event_loop, ()) + _thread.start_new_thread(run_app, ()) print("Event loop started in background thread") except Exception as e: print("Error starting event loop thread:", e)