队列:queue queue is especially useful in threaded programming when information must be exchanged safely between multiple threads. 有三种队列模式 class queue.Queue(maxsize=0) #先入先出 class queue.LifoQueue(maxsize=0) #last in fisrt out class queue.PriorityQueue(…
1,生产者消费者模型.py import random import time from multiprocessing import Queue, Process def producer(name,food,q): for i in range(4): time.sleep(random.randint(1,3)) f = '%s生产了%s%s'%(name,food,i) print(f) q.put(f) def consumer(q,name): while True: food =…
由于GIL的存在,python一个进程同时只能执行一个线程.因此在python开发时,计算密集型的程序常用多进程,IO密集型的使用多线程 1.多进程创建: #创建方法1:将要执行的方法作为参数传给Process from multiprocessing import Process def f(name): print 'hello',name if __name__ == '__main__': #需要注意的是,多进程只能在main中执行 p = Process(target=f,args=(…