-
QuestionHey, For my readout routine I've been useing threads and I've seen the asyncio secition on the deocumentation. So my question is, if I code my app like this, with threading, it's not the ideal way (I'm not familiar with asyncio)? And can matplotlib plots be rendered live (not as image), with the NavigationToolbar etc? Code sampleimport flet as ft
from threading import Thread,Event
class MyThread(Thread):
threadTime = 1
update = False
counter = 0
def __init__(self, event):
Thread.__init__(self)
self.stopped = event
def run(self):
while not self.stopped.wait(self.threadTime):
self.counter += 1
print(self.counter)
self.update = True
def main(page: ft.Page):
t = ft.Text(value="Hello, world!", color="green")
number = ft.Text(value=0, color="red")
page.controls.append(t)
page.controls.append(number)
page.update()
while(True):
if counting_thread.update == True:
counting_thread.update = False
number.value = number.value+1
page.update()
stopFlag = Event()
counting_thread = MyThread(stopFlag)
counting_thread.start()
ft.app(target=main) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There is nothing wrong with using threads when waiting for input from an external source (Database or Device). If it's working for you just go ahead and do it. In my app I have a minimum of 3 threads running at a time with no problems (maximum 6) |
Beta Was this translation helpful? Give feedback.
There is nothing wrong with using threads when waiting for input from an external source (Database or Device). If it's working for you just go ahead and do it.
In my app I have a minimum of 3 threads running at a time with no problems (maximum 6)