4 ms·
Disclaimer - I have not used AsyncIO. I have, however, tried to implement things on top of Twisted, from which this framework derives many concepts. Asynchrono
by falcolas 12y ago
Disclaimer - I have not used AsyncIO. I have, however, tried to implement things on top of Twisted, from which this framework derives many concepts.
Asynchronous programming in Python is a real pain in the butt. If I were writing a web frontend where performance mattered enough that Django/Flask would not cut it, I would use a language designed for performance.
I'm not the only one: the python development market has collectively chosen Django won out over twisted. No matter how bad Django can be with all of its corner cases, writing for it is still better than writing Twisted code. I imagine this will carry over to AsyncIO as well.
As a side note, note terribly impressed with the source. Hiding the word "dick" in unicode doesn't mean it's not there.
- raverbashing 12y agoI'd say that simply writing things in an async way is a bad way of premature optimization Yes, you can win a benchmark with it, but for a real service, it's easier to scale it in traditional ways, or only write a part of it async.
- jonesetc 12y agoI use Tornado regularly, first for work and then adopted it in my free time. I find it to be a treat(4.1+ can even use stdlib and Tornado asyncio futures interchangeably). I've previously used Flask in the past and I find Tornado just as easy to use. I do agree that when performance matters I'd probably just move away from Python. However, when writing what is mostly a proxy server to other slow services, asyncio with Python was just easy low-hanging fruit.
- emehrkay 12y agoIm using Tornado now for a personal project and I find that the async decorators makes things a breeze. Go seems really attractive when it comes to concurrency/async things. I'll probably move there if I ever do make a move.
- GMLudo 12y agoRead aiohttp.web documentation: API is really easy compare to Twisted. From my point of view, you can write very easily WebServices without headaches. About "dick" in the sub-title, I've changed a little bit a common French expression: "avec ma bite et mon couteau".
- IgorPartola 12y agoIt has been long established that using Twisted's web capabilities is a bad idea. It has been broken from the usability point of view for a very long time and I don't think it will ever be fixed. Without reciting the entire history, Tornado got a lot of crap for not just fixing what Twisted had going on, but creating a new framework from scratch. Having worked with both, I see why they did it. Basically, if you have a bad experience with Twisted + web, you are very much not alone but the fault is with Twisted, not Python. Here's how I break it down: If you need async networking at the TCP or UDP level, use Twisted. If you want a web application, use Django. If you want a one page landing page type application, use Flask. If you are on a restricted budget and need really good performance for your web application that you tried and couldn't extract from Django, go with Tornado.
- makmanalp 12y agoI'll just add, if you want a simple REST API server, flask works well. Here's an example of async with flask and sqlalchemy: https://github.com/kljensen/async-flask-sqlalchemy-example https://github.com/kljensen/async-flask-sqlalchemy-example
- raverbashing 12y agoCorrect, I was going to mention that If you need a "CMS style" web application go for Django, now if it breaks too much from that you might want to try Flask/Pylons/Pyramid
- klibertp 12y ago> that using Twisted's web capabilities is a bad idea Isn't async just a bad fit for a typical Web page? Two things which take most time per request (in my experience) are DB queries and rendering templates. While you can have async DB driver (only for postgres right now), all the template engines do their job synchronously, which - with async event loop - blocks everything until finished. There's deferToThread in Twisted, but if we're going to use a pool of threads anyway, what's the point? I also thought this problem was mostly solved with Nginx and uWSGI. This setup works extremely well in my experience, eliminating problems with handling too many sockets and such but allowing to write Django code as usual. Async is good if you mostly do things which can be asynchronous, like fetching things over the net, reading files from disk, communicating with Redis and DB. You really need pre-emptive scheduler for tasks (not necessarily threads, see Erlang) for anything that's going to be CPU-bound. And it's not true that rendering web pages is 100% IO-bound - not when you're using Python, Django and need consistently ~100ms response times.