我正在运行一个aiohttp服务器 . 它一个接一个地要求,并且工作正常 .

from aiohttp import web

async def hello(request):
    return web.Response(text='done')

app = web.Application()
app.add_routes([web.get('/', hello)])

web.run_app(app)

现在我需要逐个发出两个慢速传出请求 . 我想将aiohttp客户端代码放入hello函数中 . 因此,当服务器等待返回的出站请求时,它可以为下一个入站请求提供服务 .

async def hello(request):


        async def fetch(session, url):
            with async_timeout.timeout(10):
                async with session.get(url) as response:
                    return await response.text()

        async def main(loop):
            async with aiohttp.ClientSession(loop=loop) as session:
                html1 = await fetch(session, URL1)
                html2 = await fetch(session, URL2)

        loop = asyncio.get_event_loop()
        loop.run_until_complete(main(loop))

    return web.Response(text='done')

上面的html1和html2会同时出现 . 第一次提取完成后如何进行第二次提取?或者其他一些设计可以帮忙吗?