当第i=5的时候,按道理说就要跳出for in 循环,也就是总共执行5次rest函数,为什么我这个的确能并发执行3次,总共执行完15次rest函数。想不明白了,求解?
import queue
import threading, time
def rest(que):
while not que.empty():
q_name = que.get()
time.sleep(5)
print(q_name + ' > wake up.')
q = queue.Queue()
for i in range(1, 16):
q.put('dev %d' % i)
max_thread = 5
ts = []
for i in range(max_thread):
t = threading.Thread(target=rest, args=(q,))
t.start()
ts.append(t)