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