Multiprocessing 学会多进程 (莫烦 Python 教程)笔记-2-queue进程输出
import multiprocessing as mp
def job(q):
res = 0
print('aaaaaa')
for i in range(1000):
res += i+i**2+i**3
q.put(res) #queue
if __name__ == '__main__':
q = mp.Queue()
p1 = mp.Process(target=job,args=(q,))
p2 = mp.Process(target=job,args=(q,))
p1.start()
p2.start()
p1.join()
p1.join()
res1 = q.get()
res2 = q.get()
print(res1)
print(res2)
#out:
aaaaaa
aaaaaa
249833583000
249833583000