相关疑难解决方法(0)

Python Threads对象追加到列表

我在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)

我认为将线程对象追加到列表是一种好习惯,但是我不知道为什么要这样做?

python multithreading

2
推荐指数
1
解决办法
8819
查看次数

标签 统计

multithreading ×1

python ×1