python销毁线程_PyQt5 QThread:线程仍在运行时被销毁

我试图弄清楚为什么这些代码在线程完成后再次运行它们时会崩溃。在

我第一次点击“开始5线程”,它运行良好,结束。但如果我再按一下。整个程序崩溃了,我得到了QThread:Destroyed,而线程仍在运行错误

这个代码是在网上找到的。我正在努力从中学习。在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 description: emitted every step through work() loop

sig_done = pyqtSignal(int) # worker id: emitted at end of work()

sig_msg = pyqtSignal(str) # message to be shown to user

def __init__(self, id: int):

super().__init__()

self.__id = id

self.__abort = False

@pyqtSlot()

def work(self):

"""

Pretend this worker method does work that tak

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值