20.multi_case05

时间:2022-07-25
本文章向大家介绍20.multi_case05,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#coding:utf-8
# 通过gather方法

import asyncio

async def a(t):
    print('-->', t)
    await asyncio.sleep(0.5)
    print('<--', t)
    return t * 10

def main():
    futs = [a(t) for t in range(6)]
    print(futs)
    ret = asyncio.gather(*futs)
    print(ret)

    loop = asyncio.get_event_loop()

    ret1 = loop.run_until_complete(ret)

    print(ret1)

main()