我正在学习用于异步编程的 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.select是where the magic happens .
关于python - 异步事件循环如何知道等待资源何时准备就绪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38831687/