1. The asyncRun call can put the coroutine into the event queue. The loop is the entrance to the event loop (also called the scheduler). The loop call will hand over the thread control to the coroutine scheduler.
2. The scheduler will continuously extract coroutines or ordinary functions from the event queue in the future, and then execute and schedule them.
During the scheduling and execution process, these events may generate more events, so they will continue to execute.
Example
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()
The above is the detailed content of What is the process of python coroutine scheduling?. For more information, please follow other related articles on the PHP Chinese website!