from multiprocessing import Queue
from threading import Thread
import time
def producer(q, n):
print("开始生产")
for i in range(n-99, n+1):
print("生产{}".format(i))
q.put(i)
if i == 80 or i == 180:
time.sleep(2)
print("结束生产")
def customer(q):
print("开始消费")
while 1:
data = q.get()
print("消费者获取值:{0}".format(data))
if __name__ == '__main__':
q = Queue()
pro = Thread(target=producer,args=(q, 100))
pro2 = Thread(target=producer,args=(q, 200))
cus = Thread(target=customer,args=(q,))
pro.start()
pro2.start()
cus.start()
