Comments (3)
In my opinion the following greatly simplifies explaining Asyncio.
Explanation: There are a bunch of fancy terms in asynchronous programming but they can all essentially be explained as 'context' and 'context switching'. A thread, a task, a process are all essentially the same thing, they are differently sized 'contexts environments'. Multithreading or multiprocessing is essentially context switching(sometimes between cpus). Asyncio in python is context switching for a very small 'context environment'. Tasks are slightly larger 'context environment', threads are larger than task, and process is larger than thread(and introduces cpu's). You cant have alot of threads and processes because of the context environment overhead taking up a bunch of memory, but you can have many async awaits because there is little to no overhead.
I could be wrong but its the best way to understand it quickly in my opinion.
from pysheeet.
Thank for your suggestions. Recently, many languages introduce async/await into their syntax such as javascript. However, the hardest for me was that Python mixed generator and async/await together because Python used generator to implement a user space scheduler. That is why I created this issue for explaining how this scheduler work.
from pysheeet.
I'm not familar with Python's use of a generator to implement a user space scheduler, but I am familiar with Pythons scheduler and have experimented with pythons async generators. Async generators are the most confusing thing in python imo. Maybe I can break it down with my context and context switching idea(ive yet to try breaking it down because my realization about asyncio essentially being context saving and context switching has only come in the last year).
yield = save context state and switch context to the calling function
await = yield from = save context state of function being awaited(yielded from) and switch context to the awaiting function
async = keyword that tells the calling function that it must be awaited(aka 'awaited' aka 'yielded from' aka context state of function being awaited is saved)
An async generator is then a function that 'async/awaits' meaning it must save the context of the function being awaited (yielded from) then switch the context to the calling function(itself) and it 'yields' meaning it must save its own context too(then switch the context to the calling function). I imagine it becomes relevant when dealing with many calls to a function that calls a function with a large loop maybe in a server or scheduler idk. I bet there are very very few mainstream libs that utilize async generators and legitimately require them.
from pysheeet.
Related Issues (20)
- DateTime Column is not coded properly HOT 3
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Migrate alll codes to just python 3 HOT 6
- mapper() func is deprectiated HOT 1
- There doesn't seem to be any coverage of 'map()'
- c o
- /%0在@
- 国-酩酊大醉 ***★......ᄒ笔7卤
- P. List
- Weird variable name
- pep-0328 - guido-s-decision
- Default to Python 3 compatibility HOT 3
- New version of fundamental cheat sheets
- Review advanced cheat sheets
- Add boto3
- Appendix: Why does Decorator Need @wraps
- Cheatsheet for string manipulations HOT 4
- Iterator 404 HOT 1
- sqlalchemy cheat sheet: Reflect=True is depreciated. Change to use the reflect() method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pysheeet.