# -*- coding: utf-8 -*-
import multiprocessing
from multiprocessing import Pool, Manager
import os, time
def reader(q):
for i in range(q.qsize()):
print("reader从Queue获取到消息:%s" % (q.get(True)))
def writer(q):
data = [11,22,33,44]
for temp in data:
q.put(temp)
if __name__ == '__main__':
print("(%s) start " % os.getpid())
q = Manager().Queue() # 消息队列解耦
po = Pool()
po.apply_async(writer, (q, ))
time.sleep(1) # 先让上面的任务向Queue存入数据,然后再让下面的任务开始从中读取数据
po.apply_async(reader, (q,))
po.close()
po.join()
print("%s End" % os.getpid())
【Python】进程
最新推荐文章于 2024-06-28 11:51:44 发布