Python使用生成器实现生产者消费者模式

来源:互联网 发布:js鼠标移开div消失 编辑:程序博客网 时间:2024/06/05 12:34
import threadingimport time# 消费者def consumer():    data = ''    while True:        r = yield data        data = '生产的'+r+'还不错'        time.sleep(1)# 生产者def produce(con):    con.send(None)    for i in range(5):        print('生产者生产了%d' % i)        r = con.send(str(i))        print(r)m = consumer()produce(m)
阅读全文
0 0
原创粉丝点击