0
点赞
收藏
分享

微信扫一扫

python异步生成器


async def ticker (delay, to):
"""产生0到to的数字每delay 秒。"""
for i in range(to):
yield i
await asyncio.sleep(delay)
async def printNum():
async for i in ticker(1, 5):
print(i)

import asyncio
loopPrint = asyncio.get_event_loop()
try:
loopPrint.run_until_complete(printNum())
except:
pass
异步生成



举报

相关推荐

python 生成器

Python生成器

python生成器

python-生成器

Python之生成器

0 条评论