python - 异步事件循环如何知道等待资源何时准备就绪?

标签 python asynchronous python-asyncio

我正在学习用于异步编程的 Python asyncio。我知道事件循环会监视 Future 对象,直到它们准备就绪,然后恢复适当的协程以在 await 关键字出现的位置继续执行。

当你使用像 asyncio.sleep 这样的东西时,这是很容易理解的,因为休眠函数知道它需要多少时间,所以会知道事件循环,但是依赖的东西会发生什么在等待时间未知的网络(例如)上?

事件循环如何知道资源何时准备好或从某个来源收集数据需要多少时间?

最佳答案

How does the event loop know when a resource is ready or how many time will take to gather data from some source?

默认事件循环(基于 SelectorEventLoop )使用 selector模块跟踪所有要监视的资源,并在新数据准备就绪时得到通知。 BaseSelector.selectwhere the magic happens .

关于python - 异步事件循环如何知道等待资源何时准备就绪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38831687/

相关文章:

python - 在Python中,如何使用super作为类属性?

c# - 在 C# 中执行异步触发时省略 await 语句并忘记使用 ado.net 写入数据库是否安全

javascript - 无法在 'complete' 函数之外获得 Papa Parse 结果

python-3.x - async def 和协程,链接是什么

python - 将 tqdm 进度条与 asyncio 结合使用

python - 我的一些协程没有(总是)启动

python - brew 安装 python3 后出现 SSL 错误

python - Tensorflow numpy 图像 reshape [灰度图像]

node.js - 我可以在 Node.js 的 for 循环中允许 "breaks"吗?

python - 如何设置 ttk.Entry 的文本?