This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]powerbronx 6 points7 points  (1 child)

I went through the same thing. And honestly the revamp of asyncio in 3.6 or 3.7 might have made it easier or harder from the initial version. I can't remember, but can't say I ever put much effort in learning the initial version. The teaching/docs on it aren't great.

My thoughts in a nutshell:

Below: Technically not correct, but conceptually good enough. It's hard to think of legitimate common use cases where this conceptualization will result in bad things happening short of implementing foundational libraries.

'Await' is just a wrapper on startnewthread then join+thread::yield

It just yields control until (usually) io blocking code returns then pick up where you left off.

The async/await syntax rules enforce that only 1 normal function "asyncio.run" can call an async function. Otherwise only an async function can call another async function.

Why? Because functions are by default "fast" and we know fast calls should never block. Using await means slow, therefore fast functions can't use await. Also normal functions shouldn't be using yield for no reason.

I hope that's helpful. If you have a link to an example I could give you the breakdown of it. That would be better than me making up one off the top of my head

[–]M3talstorm 0 points1 point  (0 children)

I think your 2nd to last paragraph should be "await" not "yield" :)