简体   繁体   中英

Will “break” kill a thread running a while loop?

I am asking this because I have seen multiple answers that may be the answer, but I can't be sure. So I'm asking it here in case someone else searches for it later.

My code is a tkinter program. The gui runs in one class, whilst other clases can be run as threads. This is the code I use to set up a thread to prevent blocking the gui.

class RefreshVoyageClass(threading.Thread):

    def __init__(self, *args, **kwargs):

        threading.Thread.__init__(self, *args, **kwargs)
        self.daemon = True
        self.start()

    def run(self):
        while True:
            #some code here
            if check a certain condition:
                break

So here is my question. If that break is encountered inside the class. Will it just stop the function, but leave the thread intact, or will using break end the thread as it's completed it's task?

在您的代码中,如果遇到中断,则run函数将返回,因此线程将完成其任务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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