News for hackers. Stuff that matters.
Re:Why do we need Flask, Celery, and Redis? (2019) by meowface on Saturday April 18, 2020 @10:01AM (#22907776)
They're just completely different models. gevent is green threads, asyncio is explicit coroutines. In gevent, you don't use an "async" or "await" syntax. You just spawn greenlets (green threads), which run in the background, and if you want, you can have them block until they return a result. And they're efficient, so you can spawn thousands without a problem.
Re:Why do we need Flask, Celery, and Redis? (2019) by quacker on Saturday April 18, 2020 @11:53AM (#22908536)
I always considered "green threads" and "coroutines" to be the same thing? Are they not?
Re:Why do we need Flask, Celery, and Redis? (2019) by zenhack on Saturday April 18, 2020 @08:10PM (#22912246)
The difference is that with coroutines, yielding is explicit. Tight-looping will hog the CPU, and a blocking call will block other coroutines too. Typically "green threads" are semantically just threads but cheaper. They're scheduled independently, so there's no risk of them hogging the CPU, and you can use synchronous apis. The one downside is that you need explicit synchronization between them, whereas with coroutines you can mutate shared data structures and not worry about race conditions as long as you don't yield in between.
Re:Why do we need Flask, Celery, and Redis? (2019) by infinite8s on Saturday April 18, 2020 @01:13PM (#22909185)
They are both built on the same technology in the CPython runtime.