环境:Ubuntu14.04 python2.7.6
源码:
#!/usr/bin/python
from multiprocessing import Process, Queue
import os, time, random
def q_write(queue):
enter = ''
while 'quit' != enter:
enter = raw_input('Colben_cmd>>')
queue.put(enter, block = True)
print 'End of q_write'
def q_read(queue):
value = ''
while 'quit' != value:
value = queue.get(block = True)
print 'Return>>%s.'%(value)
print 'End of q_read'
if '__main__' == __name__:
q = Queue()
sub_write = Process(target = q_write, args = (q, ))
sub_read = Process(target = q_read, args = (q, ))
sub_write.start()
sub_read.start()
sub_write.join()
sub_read.join()
print 'End of parent process'