首页 > 解决方案 > 守护线程自动停止?

问题描述

这是一个场景:

档案一:

from fileb import StatusClass

class MainClass (tk.Tk):
    #init
    ...
    self.anotherclass = StatusClass(parent, controller)

    #DOSOMESTUFF

    self._startprgram() 

文件 B:

class StatusClass (tk.Frame):
    #init
    ...
    self.anotherclass = StatusProcess


class StatusProcess (threading.Thread):
    #init method
    self.setDaemon(True)

    def run():
        while True:
            #do stuff

发生的情况是,根据文件 A 中#DOSOMESTUFF 中的运行时间,创建的线程会停止。

如果我有一些指令,它会保留,但如果我什至添加 time.sleep 几秒钟,线程也会停止。有什么建议吗?

标签: pythonmultithreadingtkinterpython-multithreading

解决方案


推荐阅读