import time, random
import queue, threading
q = queue.Queue()
def Producer(name):
count = 0
while count < 10:
print('making......')
time.sleep(random.randrange(3))
q.put(count)
print('Producer %s has produced %s baozi.' % (name, count))
count += 1
q.task_done()
print('ok......')
def Consumer(name):
count = 0
while count < 10:
q.join()
print('waiting......')
time.sleep(random.randrange(4))
data = q.get()
print(data)
print('\033[32;1m食客吃了%s个包子\033[0m' % count)
count += 1
p1 = threading.Thread(target=Producer, args='A')
c1 = threading.Thread(target=Consumer, args='B')
p1.start()
c1.start()
08-15
08-15
08-15