from multiprocessing import Process, Queue
import os, time, random
def write(q):
print('process to write: %s' % os.getpid())
for value in ['A', 'B', 'C']:
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' % value)
if __name__=='__main__':
q=Queue()
pw=Process(target=write, args=(q,))
pr=Process(target=read, args=(q,))
pw.start()
pr.start()
pw.join()
pr.terminate()# your code goes here
ZnJvbSBtdWx0aXByb2Nlc3NpbmcgaW1wb3J0IFByb2Nlc3MsIFF1ZXVlCmltcG9ydCBvcywgdGltZSwgcmFuZG9tCgoKZGVmIHdyaXRlKHEpOgogICAgcHJpbnQoJ3Byb2Nlc3MgdG8gd3JpdGU6ICVzJyAlIG9zLmdldHBpZCgpKQogICAgZm9yIHZhbHVlIGluIFsnQScsICdCJywgJ0MnXToKICAgICAgICBwcmludCgncHV0ICVzIHRvIHF1ZXVlLi4nICUgdmFsdWUpCiAgICAgICAgcS5wdXQodmFsdWUpCiAgICAgICAgdGltZS5zbGVlcChyYW5kb20ucmFuZG9tKCkpCgpkZWYgcmVhZChxKToKICAgIHByaW50KCdwcm9jZXNzIHRvIHJlYWQ6ICVzJyAlIG9zLmdldHBpZCgpKQogICAgd2hpbGUgVHJ1ZToKICAgICAgICB2YWx1ZT1xLmdldChUcnVlKQogICAgICAgIHByaW50KCdnZXQgJXMgZnJvbSBxdWV1ZScgJSB2YWx1ZSkKCmlmIF9fbmFtZV9fPT0nX19tYWluX18nOgogICAgcT1RdWV1ZSgpCiAgICBwdz1Qcm9jZXNzKHRhcmdldD13cml0ZSwgYXJncz0ocSwpKQogICAgcHI9UHJvY2Vzcyh0YXJnZXQ9cmVhZCwgYXJncz0ocSwpKQogICAgcHcuc3RhcnQoKQogICAgcHIuc3RhcnQoKQogICAgcHcuam9pbigpCiAgICBwci50ZXJtaW5hdGUoKSMgeW91ciBjb2RlIGdvZXMgaGVyZQ==