python - 为什么需要等待 resp.text()?

标签 python async-await python-asyncio

在以下 Python 异步代码示例中,为什么等待 .text()?

async with aiohttp.ClientSession() as session:
    async with session.get('http://httpbin.org/get') as resp:
        return await resp.text()

看起来从响应中获取文本将是即时的并且不会被阻塞。

最佳答案

获取文本需要等待整个响应下载完毕,这对于较大的响应或在慢速网络上可能需要一些时间。

关于python - 为什么需要等待 resp.text()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56615579/

相关文章:

python - 使用 Wing IDE 调试多线程 Python

python - 在不减少总数的情况下删除列表的项目

python - 按范围对数据进行分组时如何更改 bin 大小?

flutter - 如何使用 yield 返回错误(from catch error)

python - Python中的 `await`是否会屈服于事件循环?

asynchronous - Dart - future 中的 future 无法正常运行

python - 使用掩码和多重映射替换列值

python - 将任务添加到 python asyncio

python - 如何抑制 "coroutine was never awaited"警告?

python - 文件异步下载