我在python中学习多线程。我经常看到程序使用多线程时,它将线程对象附加到一个列表中,如下所示:
# imports
import threading
import time
def worker():
print "worker...."
time.sleep(30)
threads = []
for i in range(5):
thread = threading.Thread(target=worker)
threads.append(thread)
thread.start()
Run Code Online (Sandbox Code Playgroud)
我认为将线程对象追加到列表是一种好习惯,但是我不知道为什么要这样做?