From fd9996d729cad23f42b48dcffcca8f0752a86e07 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sun, 20 Apr 2025 12:07:29 +0200 Subject: [PATCH] Subthread demo Launching threads works fine, which is great. When the main app gets killed because "Referenced object was deleted!", the sub threads don't die, they stay active... --- appstore.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/appstore.py b/appstore.py index 85ada50d..4c083a46 100644 --- a/appstore.py +++ b/appstore.py @@ -524,7 +524,22 @@ print("Child coroutine: Exiting") app2_script = """ import time -print("Child coroutine: Creating UI") +import _thread +print("App2 running") + +# Quit flag +should_continue = True + +def app2_thread(): + count=0 + while should_continue: + print(f"app2_thread: thread_id {_thread.get_ident()} - {count}") + count+=1 + time.sleep(4) + +_thread.start_new_thread(app2_thread, ()) + + # Label label = lv.label(subwindow) label.set_text("App2: 0") @@ -541,8 +556,6 @@ slider = lv.slider(subwindow) slider.set_range(0, 100) slider.set_value(50, lv.ANIM.OFF) slider.align(lv.ALIGN.BOTTOM_MID, 0, -30) -# Quit flag -should_continue = True # Button callback def button_cb(e): global should_continue @@ -554,6 +567,9 @@ def slider_cb(e): value = slider.get_value() #print("Child slider value:", value) slider.add_event_cb(slider_cb, lv.EVENT.VALUE_CHANGED, None) + + + # Update loop count = 0 while should_continue: