有些人可以向我解释为什么有时会挂起来吗? (这只是为了学习目的,我不会对这样的列表求和)
import multiprocessing as mp
q = mp.JoinableQueue()
def worker():
S = 0
while not q.empty():
S += q.get()
q.task_done()
print(S)
procs = []
for i in range(1000):
q.put(i)
for i in range(2):
t = mp.Process(target=worker)
t.start()
procs.append(t)
q.join()
for t in procs:
t.join()