【发布时间】:2021-09-03 10:33:49
【问题描述】:
我正在编写一个 Kivy 应用程序,其中用户提供各种输入,然后单击一个按钮,该按钮应该调用一系列 python 函数,这些函数在顺序后台线程中运行,同时在 GUI 中更新进度条。我有三个函数应该一个接一个地调用,在前一个函数完成并且进度条为 100% 之后,进度条返回 0% 并报告下一个函数的进度等。问题是,如果我按顺序调用它们,看起来它们在后台同时运行,只有最后一个更新进度条。如何设置线程仅在前一个线程完成后才被调用?
我尝试了join 方法,但它只是通过将线程放在主线程上来冻结 GUI。
这是按下按钮时调用的当前函数:
scripts_to_run = ListProperty([])
def process_data(self):
to_run = []
if "move_data" in self.scripts_to_run:
self.move_data()
to_run.append(Thread(target=self.produce_data_file))
if "histograms" in self.scripts_to_run:
to_run.append(Thread(target=self.histograms))
if "log_histograms" in self.scripts_to_run:
to_run.append(Thread(target=self.log_histograms))
for thread in to_run:
thread.start()
【问题讨论】:
标签: python kivy kivy-language