比较简单,直接插入代码
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import multiprocessing
import time
def download(q):
"""
模拟下载
"""
data = [11,22,33,44]
# 向队列中写入数据
for temp in data:
q.put(temp)
print("写入完成。。。")
def analysis(q):
"""
模拟分析
"""
waiting = list()
# 从队列中获取数据
while True:
data = q.get()
waiting.append(data)
if q.empty():
break
print(waiting)
def main():
# 创建一个队列
q= multiprocessing.Queue()
# 创建多个进程,将队列的引用当做实参进行传递
p1 = multiprocessing.Process(target=download,args=(q,))
p2 = multiprocessing.Process(target=analysis,args=(q,))
p1.start()
time.sleep(1)
p2.start()
if __name__ == '__main__':
main()