简体   繁体   English

如何正确停止 pyqt5 QThread?

[英]How to correctly stop pyqt5 QThread?

There is a program for pyqt5. pyqt5 有一个程序。 It has a thread (qthread) in which you need to perform some action with a certain front end.它有一个线程(qthread),您需要在其中对某个前端执行一些操作。 I used QThread.msleep to define this period, and the flag that came out of the while cycle.我使用 QThread.msleep 来定义这个时间段,以及从 while 循环中出来的标志。 But if the period is long, then it will take a long time to wait for the exit from the loop, and I want to finish it as soon as I click on the button in the GUI (but not kill, start again soon).但是如果周期很长,那么等待退出循环需要很长时间,我想在GUI中点击按钮就完成它(但不是杀死,很快重新开始)。 The source code is pretty standard here, I need ideas.源代码在这里很标准,我需要想法。
An example of an exaggerated class for a separate thread.用于单独线程的夸张 class 示例。

class intrhead(QObject):
    ...
    def run(self):
        while(flag):
            ...
            QThread.msleep(period)

The correct solution is to split the period.正确的解决方案是拆分期间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM