from PyQt5.QtCore import QThread, pyqtSignal import time class MyThread(QThread): finished = pyqtSignal() def run(self): print('Thread started.') time.sleep(5) # 模拟一个耗时任务 print('Thread finished.') app = QApplication([]) thread = MyThread() thread.start() # 在任何你需要停止线程的时候 thread.wait() print('Thread stopped.')
#############################