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()
posted @ 2019-05-06 17:06  hank-li  阅读(83)  评论(0编辑  收藏  举报