import time import asyncio
async def hello(): print('Hello World:%s' % time.time())
def run(): for i in range(5): loop.run_until_complete(hello())
loop = asyncio.get_event_loop() if name =='main': run()
Hello World:1562248241.350658 Hello World:1562248241.350658 Hello World:1562248241.350658 Hello World:1562248241.350658 Hello World:1562248241.350658
import asyncio from aiohttp import ClientSession
tasks = [] url = "https://www.baidu.com/{}" async def hello(url): async with ClientSession() as session: async with session.get(url) as response: response = await response.read() print(response)
if name == 'main': loop = asyncio.get_event_loop() loop.run_until_complete(hello(url))
import asyncio
async def main(): print('Hello ...') await asyncio.sleep(1) print('... World!')
asyncio.run(main())