# -*-coding:utf-8-*- __author__ = ‘magicpwn‘ import multiprocessing import Queue def worker(): print ‘worker‘ return q = Queue.Queue(1000) def producer(): for i in range(1000): q.put(i) def consumer(): for i in range(1000): print q.get(), q.qsize() # 进程不能使用queue # k = multiprocessing.Process(target=producer) # sh = multiprocessing.Process(target=consumer) # k.start() # sh.start() # 多进程声明和使用同线程,但通信不能使用queue. if __name__ == ‘__main__‘: jobs= [] for i in range(5): p = multiprocessing.Process(target=worker) jobs.append(p) p.start()
本文出自 “magicpwn” 博客,请务必保留此出处http://magicpwn.blog.51cto.com/10497784/1684855
原文地址:http://magicpwn.blog.51cto.com/10497784/1684855