DEV Community

Discussion on: Is Python’s asyncio Worth It?

Collapse
 
pembeci profile image
pembeci

I am currently working on a realtime Django channels project which needs to fetch data from a REST api and AMQP server. Fetched data need to be processed in a very fast manner and pushed to web clients. There is also Redis involved. This was my first time using asyncio but I am quite happy with how the code is shaping and its performance. Your mind is free from dealing with race conditions or moving data between threads. You need to adapt your thinking to the concept of coroutines and the event loop but it happens quickly (i.e. easy learning curve) and from what you said in your post I guess it will be a no problem for you too. I guess other languages you mentioned already offers this without the need to fight the GIL but to me asyncio is a good enough abstraction to have the same in Python.

One downside is once you are into the async world you need compatible libraries to get the most out of it. Luckily for me aiohttp and aioredis is already available and stable. For amqp I chose kombu which is not yet asyncio compatible (but next major version will be) but Django channels provides something called background workers and integrating kombu wasn't a problem.

More specific answers to your questions:

1) I am not familiar with Rust or Clojure yet but I'll definitely choose Python and asyncio over Java or C++ threads if I need concurrency mainly for dealing with network bound slow operations. Pros of Python will beat whatever cons asyncio has for me.

2) I guess this depends mostly on the complexity of the project and what dependencies you need. If it includes an ORM library for instance which is not async, it can be a pain to adapt it to asyncio. Before starting this project I checked Twisted and eventlet and I found them complex for my needs. Asyncio offered a much simpler way of having concurrency and results so far are good as I said.