我只希望有一个线程是活动的,下面是算法:
def myfunction(update):
if threading.activeCount >=1:
# kill all previous threads
while true:
# some execution
while true:
t = threading.Thread(myfunction, args=([update]))
t.start()所以在这里线程在我的函数中处于无限循环,所以在启动新线程之前,我需要关闭前一个线程,请指导我。
发布于 2014-12-24 01:34:51
您不能杀死线程,您的函数必须以某种方式返回。因此,诀窍是以这样一种方式编写您的函数:它知道什么时候停止它所做的事情并返回。当然,这与环境有关。通常情况下,将代码实现为一个具有“close”方法的类,该方法知道要做什么。例如,
https://stackoverflow.com/questions/27630185
复制相似问题