Eventlet vs. Asyncio

Explicit and implicit concurrency in Python.

.. With asyncio, an event loop runs and is in charge of switching between various coroutines. The main difference between asyncio and eventlet is that switching is performed explicitly. I have to use yield from in my coroutine if I wish to indicate that I’m ready to be switched out.

AsyncIO for the Working Python Developer

By using yield from on another coroutine we declare that the coroutine may give the control back to the event loop, in this case sleep will yield and the event loop will switch contexts to the next task scheduled for execution: bar. Similarly the bar function yields from sleep which allows the event loop to pass control back to foo at the point where it yielded, as it happens with all generators.

How Celery fixed Python’s GIL problem

I think the main problem we have at the core of Python is that it’s heavily inspired by C. But I think in this case it’s Python’s weakness.

.. There are hundreds of companies running Python code as glue logic – and that’s single-threaded synchronous code (check how popular Django is) yet somehow those companies handle tens of thousands of users.

I think that if we want to support full concurrency in Python, this is the way to go. Introduce primitives for fully lockless paradigm using queues and enable programmers to define queues.

Most of it is already implemented in Celery. To have that in Python we’d need to extend the interpreter to manage workers and queues as they’re needed, add some syntax sugar to enable nested tasks definition and dispatch and you’re mostly good to go.

Asynchronous Tasks With Django and Celery

When I was new to Django, one of the most frustrating things I experienced was the need to run a bit of code periodically. I wrote a nice function that performed an action that needed to run daily at 12am. Easy, right? Wrong. This turned out to be a huge problem to me since at the time I was used to “Cpanel-type” web hosting where there was a nice handy GUI for setting up cron jobs for this very purpose.

After much research, I found a nice solution – Celery, a powerful asynchronous job queue used for running tasks in the background. But this led to additional problems, since I couldn’t find an easy set of instructions to integrate Celery into a Django Project.