我试图弄清楚为什么这个代码崩溃,如果我尝试完成第二次运行线程.
我第一次单击"开始5个线程"它运行得很好并完成.但是,如果我再次点击它.整个程序崩溃,我得到QThread:当线程仍在运行时销毁错误
此代码可在网上找到.我想从中吸取教训.
import time
import sys
from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QApplication, QPushButton, QTextEdit, QVBoxLayout, QWidget
def trap_exc_during_debug(*args):
# when app raises uncaught exception, print info
print(args)
# install exception hook: without this, uncaught exception would cause application to exit
sys.excepthook = trap_exc_during_debug
class Worker(QObject):
"""
Must derive from QObject in order to emit signals, connect slots to other signals, and operate in a QThread.
"""
sig_step = pyqtSignal(int, str) # worker id, step …Run Code Online (Sandbox Code Playgroud)