如何停止/突破线程无限 while 循环?

How to stop / break out of threading infinite while-loop?

我需要通过 stop_button 函数停止 while 循环。尝试了几种方法但失败了。寻找提示,谢谢。

def start_button():
    t1 = threading.Thread(target=thread1)
    t1.start()

def thread1():
    while True:
        start()

def stop_button():
    pass

也许这个

flag = False

def start_button():
    flag = True
    t1 = threading.Thread(target=thread1)
    t1.start()

def thread1():
    while flag:
        start()

def stop_button():
    flag = false