如果我使用Queue.Queue,那么我的read()功能不起作用,为什么?但如果我使用multiprocessing.Queue,它运作良好:
from multiprocessing import Pool, Process, Queue
import os, time
# from Queue import Queue
def write(q):
for v in ['A', 'B', 'C']:
print 'Put %s to queue ' % v
q.put_nowait(v)
time.sleep(0.2)
def read(q):
while 1:
if not q.empty():
v = q.get(True)
print "Get %s from queue" % v
time.sleep(0.2)
else:
break
if __name__ == '__main__':
q = Queue()
pw = Process(target=write, args=(q, ))
pr = Process(target=read, args=(q, ))
pw.start()
pw.join()
pr.start()
pr.join() …Run Code Online (Sandbox Code Playgroud)