我正在使用PySide6和QThread编写一个GUI应用程序。我有两个不同的QThread对象,它们运行两个长时间运行的作业,它们不能重叠,所以如果一个线程正在运行,第二个线程必须等到第一个线程结束,如何才能获得这个结果
我尝试编写一个简单的代码示例:
from PySide6.QtCore import QThread
from MyJobs import LongJob
job_a = LongJob()
job_b = LongJob()
thread_a = QThread()
thread_b = QThread()
job_a.moveToThread(thread_a)
job_b.moveToThread(thread_b)
thread_a.start()
thread_b.start() # if thread_a is running, thread_b must wait until thread_a ends, then run and viceversa
线程是工作空间,您需要管理作业的执行方式。在这种情况下,任务B必须在任务A完成时执行,反之亦然
相关问题 更多 >
编程相关推荐