python - 如何停止/跳出线程无限的while循环?
问题描述
我需要通过 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
推荐阅读
- php - 如何禁用特定路线的油门?(拉拉维尔)
- xml - Windows 配置设计器 - 配置失败
- r - 格式化数据框中的值
- python - 3d 绘图用在哪个领域?
- wpf - 拖动时WPF突出显示背景
- php - 当内容不是英文时,数据无法保存在我的数据库中
- javascript - javascripts get json 将显示 Unexpected token '&'
- java - 编写程序求圆的面积,创建对象(Java)
- cs50 - CS50 Tideman :( lock_pairs 如果创建循环则跳过最后一对
- asp.net-core - EF Core 3.1 无法将备用键标记为可选