Multithreading 在python中重新创建线程
我正在使用下面的模板来重新创建我需要无限运行的线程。 我想知道这个模板在内存方面是否是可伸缩的。线程是否被正确地销毁Multithreading 在python中重新创建线程,multithreading,python-2.7,Multithreading,Python 2.7,我正在使用下面的模板来重新创建我需要无限运行的线程。 我想知道这个模板在内存方面是否是可伸缩的。线程是否被正确地销毁 import threading import time class aLazyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): time.sleep(10) print "I
import threading
import time
class aLazyThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
time.sleep(10)
print "I don not want to work :("
class aWorkerThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
time.sleep(1)
print "I want to work!!!!!!!"
threadA = aLazyThread()
threadA.start()
threadB = aWorkerThread()
threadB.start()
while True:
if not (threadA.isAlive()):
threadA = aLazyThread()
threadA.start()
if not (threadB.isAlive()):
threadB = aWorkerThread()
threadB.start()
困扰我的是下面在eclipse中拍摄的显示调试信息的图片,看起来线程正在堆叠它
aLazyThread
),旧的threadA
值被销毁(可能不是在该点上,但不久之后)time.sleep(1)
),否则它将消耗处理器,无用地检查其他线程是否正在运行