Is `await` in Python3 Cooperative Multitasking?

前端 未结 3 727
春和景丽
春和景丽 2021-01-18 06:08

I am trying to understand the new asyncio coroutines (introduced in Python 3.5).

In 1997 I attended a course at university which roughly covered the content of the

3条回答
  •  被撕碎了的回忆
    2021-01-18 06:36

    Inside a coroutine function, the await expression can be used to suspend coroutine execution until the result is available. Any object can be awaited, as long as it implements the awaitable protocol by defining the await() method.

    A coroutine can pause execution using the await keyword with another coroutine. While it is paused, the coroutine’s state is maintained, allowing it to resume where it left off the next time it is awakened. That sounds quite like Cooperative multitasking to me. See this example

提交回复
热议问题