Re:The magic of asyncio explained
by kbaker on Tuesday August 07, 2018 @11:47PM
(#17713066)
Isn't Python's async/await syntax an implementation of green threads? I mean using await is almost exactly the cooperative scheduling idea. The article may use Futures and callbacks but you can just as easily do something like:
[ Parent
| on HN ]
They're sort of similar, and you can probably get the same work done in either system, but I think real threading (green or otherwise), may leave you with less cognitive load. Spawning a thread may be complex, and thinking about how the threads are scheduled is often complex, but what each thread does can be very simple -- and you don't have to think about 'long running things need to be futured/awaited', you just do things in a straightforward way in the thread (caveat: slightly less straightforward if you need thread actions to be cancellable).
Green threads may be running an event loop underneath, but it's a useful abstraction in many contexts.
> ... you don't have to think about 'long running things need to be futured/awaited', you just do things in a straightforward way in the thread
https://www.youtube.com/watch?v=bzkRVzciAZg
Six years later, very little has change in the arguments about events vs threads.
> Spawning a thread may be complex, and thinking about how the threads are scheduled is often complex, but what each thread does can be very simple
And that's how it starts, and in the end it's New Year's Eve and you're somehow, again, debugging a deadlock.
> green threads
yes please
You can deadlock with futures as well. Except that with futures you do not get a (two actually) nice call stack pointing to the deadlocked resource.
Python has proper threads, and they're anything but simple.