进程间通讯

#_author:来童星
#date:2019/12/11
# 进程间通讯 
# 不同进程间内存是不共享的,要想实现两个进程间的数据交换,可以用以下方法:
# Queues
# 使用方法跟threading里的queue类似:
from multiprocessing import Process, Queue
def f(q,n):

q.put([42, n, 'hello',id(q)])
if __name__ == '__main__':
q = Queue()
print('main',id(q))
p_list=[]
for i in range(3):
p = Process(target=f, args=(q,i))
p_list.append(p)
p.start()
print(q.get())
print(q.get())
print(q.get())
for i in p_list:
i.join()


原文地址:https://www.cnblogs.com/startl/p/12025655.html