消费者生产者模式
import threading
from queue
import Queue
class Producer(threading
.Thread
):
def run(self
):
global que
while True:
if que
.qsize
() < 10:
que
.put
('这是生产者生产的数据')
class Consumer(threading
.Thread
):
def run(self
):
global que
while True:
if que
.qsize
()>0:
print(self
.name
,'消费数据',que
.get
())
if __name__
== '__main__':
que
= Queue
()
producer
= Producer
()
producer
.start
()
consumer
= Consumer
()
consumer
.start
()
转载请注明原文地址:https://tech.qufami.com/read-435.html