3 ms·
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
by kbaker 8y ago
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:
result = await fake_network_request('one')
- toast0 8y agoThey'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.
- yen223 8y agoPython has proper threads, and they're anything but simple.
- toast0 8y agoPython threads aren't simple, because of the shared everything model python uses, so any variable access requires the GIL. Shared nothing threads are much simpler to work with.
- pdkl95 8y ago> ... 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 https://www.youtube.com/watch?v=bzkRVzciAZg Six years later, very little has change in the arguments about events vs threads.
- pas 8y ago> 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
- gpderetta 8y agoYou 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.