>>线程下生产者消费者模型
# 线程下的生产者消费模型
import threading
import time
class data_base:
def __init__(self):
self.__name = None
self.__value = None
def creat_data(self, name, value):
self.__name = name
time.sleep(1)
self.__value = value
def __str__(self):
time.sleep(0.8)
return '%s---%s'%(self.__name,self.__value)
def producter(data):
for i in range(100):
if i % 2 == 0:
data.creat_data('哟西', '你是sb')
else:
data.creat_data('哟西', '他是sb')
def cossumer(data):
for num in range(100):
print(data)
def main():
data = data_base()
t1 = threading.Thread(target=producter, args=(data,))
t2 = threading.Thread(target=cossumer, args=(data,))
t1.start()
t2.start()
t1.join()
t2.join()
if __name__ == '__main__':
main()