# -*-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()
时间: 2024-11-04 17:10:37