作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
为了简化我遇到的情况:我试图在线程仍在 Python 2.7 中运行时终止它,但我不确定该怎么做。
使用这个简单的代码:
import time
import threading
def thread1():
print "Starting thread 1"
while True:
time.sleep(0.5)
print "Working"
thread1 = threading.Thread(target=thread1, args=())
thread1.start()
time.sleep(2)
print "Killing thread 1"
thread2.stop()
print "Checking if it worked:"
print "Thread is: " + str(thread1.isAlive())
线程 1 继续“工作”,我试图在主线程中终止它。关于如何做的任何想法?我试过:
threat1.terminate
threat1.stop
threat1.quit
threat1.end
这一切似乎都表明,没有办法用简单的一行代码来真正阻止它。你有什么建议?
我是一名优秀的程序员,十分优秀!