0
from multiprocessing import Process,Queue
import os,time,random
def write(q):
print('Process to write:%s'%os.getpid())
for value in ['10000']:
print('Put %s to queue...'%value)
q.put(value)
time.sleep(random.random())
def read(q):
print('Process to read:%s'%os.getpid())
while True:
value=q.get(True)
print('Get %s from queue.'%(10000**10000))
if __name__=='__main__':
q=Queue()
pw=Process(target=write,args=(q,))
pr=Process(target=read,args=(q,))
pw.start()
pr.start()
if(q.empty()):
print('Queue is empty.')
else:
pass
pw.join()
pr.join()
pr.terminate
运行结果:
收藏