在python3.5之后可以使用,作用就是简化asyncio的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import asyncio async def func1(): print(1) await asyncio.sleep(2) print(2) async def func2(): print(3) await asyncio.sleep(2) print(4) tasks = [ asyncio.ensure_future(func1()), asyncio.ensure_future(func2()) ] loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(tasks)) |
