首页 > 文章列表 > python协程调度的流程

python协程调度的流程

Python 协程
416 2022-08-07

1、asyncRun调用可以将协程放入事件队列中,loop是进入事件循环(也可称为调度器)的入口,loop调用将将线程控制权交给协程调度器。

2、该调度器将在未来不断地从事件队列中提取协程或普通函数,然后执行和调度它们。

在调度和执行过程中,这些事件可能会产生更多的事件,因此它们将继续执行。

实例

from queue import Queue
 
 
class __EventQueue:
    def __init__(self) -> None:
        self.__eventQueue = Queue()
 
    def pushCallback(self, fn):
        self.__eventQueue.put(fn, block=True)
 
    def getCallback(self):
        return self.__eventQueue.get(block=True)
 
eventQueue = __EventQueue()

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。