# 使用yield生成器实现协程
# 协程:没有上下文切换开销,访问资源加锁问题
# 但不能从分利用多核
def consumer():
res = ""
while True:
n = yield res # 将res返回给send返回值,并阻塞等待下次send命令
if n is None:
return
python协程yield实现
最新推荐文章于 2025-04-30 16:50:07 发布