python多线程关闭_Python在多线程上关闭一个线程

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 19:23   2216   0

为了简化我所拥有的情况:我正在尝试终止线程,当它仍在

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

这一切似乎都指出,没有办法用简单的代码行来真正阻止它.你有什么建议吗?

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP