簡體   English   中英

如何停止/跳出線程無限的while循環?

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

我需要通過 stop_button function 停止 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM