python协程中for循环避免阻塞
直接上代码#协程版import asyncioimport timeasync def func(a): t = await asyncio.sleep(1) return a+10async def run(): time_start = time.time() a_list = [1, 2, 3, 4] ans_list = await asyncio.gather(*[func(a=a) for a in a_list]) for a,
原创
2021-07-28 22:55:03 ·
851 阅读 ·
2 评论