从概念上讲,我想完成以下操作,但在理解如何在Python中正确编码时遇到了麻烦:
from threading import Thread
for i in range(0,3):
t = Thread(target=myfunction)
t.start()
# wait until threads have finished executing
print 'complete!'
答案 0 :(得分:6)
将线程添加到列表中并join()
。
from threading import Thread
tlist = []
for i in range(3):
t = Thread(target=some_function)
t.start()
tlist.append(t)
# wait until threads have finished executing
for t in tlist:
t.join()
print 'complete!'
答案 1 :(得分:-3)
我从未使用过python,但我认为你所寻找的概念是“信号量”。
谷歌出现了这个: