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...
This commit is contained in:
Thomas Farstrike
2025-04-20 12:07:29 +02:00
parent 4ffcb6e330
commit fd9996d729
+19 -3
View File
@@ -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: