我有点理解asyncio在Python中是如何工作的,我也想知道aiohttp
包如何向事件循环发出信号,表明它正在做一些IO操作,以及事件循环应跳到下一个任务?
import aiohttp
import asyncio
async def fetch(session, url):
async with session.get(url) as response:
return await response.text()
async def main():
async with aiohttp.ClientSession() as session:
html = await fetch(session, 'http://python.org')
print(html)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())