Issue
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 book Modern Operating Systems by Andrew Tanenbaum.
Somehow the await
in Python3 reminds me at Cooperative Multitasking.
From Wikipedia:
Cooperative multitasking, also known as non-preemptive multitasking, is a style of computer multitasking in which the operating system never initiates a context switch from a running process to another process. Instead, processes voluntarily yield control periodically or when idle in order to enable multiple applications to be run simultaneously. This type of multitasking is called "cooperative" because all programs must cooperate for the entire scheduling scheme to work.
If you look at the Python interpreter like an operating system, does the term "Cooperative Multitasking" apply to await
?
But may be I am missing something.
Update 2023
Since one year I use Golang, and I like it. There are no async functions, no Promises. Go is great for concurrency.
Solution
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
Answered By - Tony Vincent
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.