#jincheng1.py
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)
陌年莫流伤
#jincheng1.py 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':
Process to read: 902 put A to queue... Get A from queue. put B to queue... Get B from queue. put C to queue... Get C from queue.