import multiprocessing
def download_date(q):
''' 下载数据 '''
# 模拟从网上下载数据
data = [11, 22, 33, 44]
# 向队列中写入数据
for temp in data:
q.put(temp)
print('---已经下载完毕--')
def analysis_data(q):
'''数据处理'''
waitting_data = list()
# 从队列中获取数据
while True:
data = q.get()
waitting_data.append(data)
if q.empty():
break
# 模拟数据出路
print(waitting_data)
def main():
# 1. 创建一个队列
q = multiprocessing.Queue()
download_process = multiprocessing.Process(target=download_date, args=(q,))
analysis_process = multiprocessing.Process(target=analysis_data, args=(q,))
download_process.start()
analysis_process.start()
if __name__ == '__main__':
main()