#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018-01-22 22:09 # @Author : hhj# @Site : # @File : yield单线程异步.pyimport time def consumer(name): print("%s 准备吃包子啦" %name) while True: baozi = yield #接收值 print("包子[%s]来了,被[%s]吃了!" %(baozi,name)) def producer(name): c = consumer("A") c2 = consumer("B") c.__next__() c2.__next__() print("我开始准备做包子了") for i in range(10): time.sleep(1) print("做了两个包子") c.send(i) #发送值 c2.send(i) producer("hhj")
原文地址:https://www.cnblogs.com/hhjwqh/p/8331472.html
时间: 2024-09-29 18:49:00