gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:07:23 24 4
gpt4 key购买 nike

我正在学习用于异步编程的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com