from multiprocessing import Process, Queue
import os, time, random
def read(q):
print('process to read: %s' % os.getpid())
while True:
value=q.get(True)
print('get %s from queue' % value)
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())
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
ZnJvbSBtdWx0aXByb2Nlc3NpbmcgaW1wb3J0IFByb2Nlc3MsIFF1ZXVlCmltcG9ydCBvcywgdGltZSwgcmFuZG9tCgpkZWYgcmVhZChxKToKICAgIHByaW50KCdwcm9jZXNzIHRvIHJlYWQ6ICVzJyAlIG9zLmdldHBpZCgpKQogICAgd2hpbGUgVHJ1ZToKICAgICAgICB2YWx1ZT1xLmdldChUcnVlKQogICAgICAgIHByaW50KCdnZXQgJXMgZnJvbSBxdWV1ZScgJSB2YWx1ZSkKCmRlZiB3cml0ZShxKToKICAgIHByaW50KCdwcm9jZXNzIHRvIHdyaXRlOiAlcycgJSBvcy5nZXRwaWQoKSkKICAgIGZvciB2YWx1ZSBpbiBbJ0EnLCAnQicsICdDJ106CiAgICAgICAgcHJpbnQoJ3B1dCAlcyB0byBxdWV1ZS4uJyAlIHZhbHVlKQogICAgICAgIHEucHV0KHZhbHVlKQogICAgICAgIHRpbWUuc2xlZXAocmFuZG9tLnJhbmRvbSgpKQoKaWYgX19uYW1lX189PSdfX21haW5fXyc6CiAgICBxPVF1ZXVlKCkKICAgIHB3PVByb2Nlc3ModGFyZ2V0PXdyaXRlLCBhcmdzPShxLCkpCiAgICBwcj1Qcm9jZXNzKHRhcmdldD1yZWFkLCBhcmdzPShxLCkpCiAgICBwdy5zdGFydCgpCiAgICBwci5zdGFydCgpCiAgICBwdy5qb2luKCkKICAgIHByLnRlcm1pbmF0ZSgpIyB5b3VyIGNvZGUgZ29lcyBoZXJl