Asynchronous servers support much larger numbers of simultaneous client connections. More conventional servers come up against thread and process limits when servicing large number of concurrent clients, particularly those with long-lived connections. Async servers can also provide better performance as they avoid the overheads of e.g. thread context switching.
As well as the
Twisted framework, there are also asynchronous server building blocks in Python’s standard library: previously
asynchat, but now also
First off Django is a framework for writing web apps so it provides ORM, html templating, it requires running an http server etc. Twisted helps to write much lower level code than that. You could use twisted to write the http server Django runs on. If you use Django you are limited to http model, with twisted it could be communicating in any protocol you like including push protocols. So for your chat example you get a server that scales better since it can push comments to people who have logged in VS with django every client having to poll repeatedly.
edited to reflect comments by: sos-skyl
- Django Full Text SearchVectorField obsolete in PostgreSQL
- Django – reverse query name clash
- One project, Multiple customers with git?
- Django Template Not Found
The biggest advantage for me is that Twisted gives me an application that has state, and can communicate with many different clients using many protocols.
For me, my Twisted server communicates with a number of sensors installed in houses and businesses that monitor power usage. It stores the data and keeps recent data and state in handy-dandy python classes in memory. Requests via xmlrpc from django get this state and can present recent data to the user. My Gridspy stuff is still in development so the actual site at your.gridspy.co.nz is a bit pre-alpha.
The best part is that you need surprisingly little code to make an effective server. An amazing amount of the work is done for you.
- In python django how do you print out an object's introspection? The list of all public methods of that object (variable and/or functions)?
- Model in sub-directory via app_label?
- Load static file with variable name in django
- Why can I access an object during it's post_save Signal, but not when I trigger code within that signal that calls it on another process
In twisted you can implement protocols of your own. Django certainly can’t do this.
- Django form with unknown number of checkbox fields and multiple actions
- DjangoRestFramework HTTPS Links With Routers and Viewsets
You could use WHIFF instead of either :). Check out
for server updates. You could probably do something similar
in Django, but I don’t know how because I gave up on Django.
btw: I’m hoping to move this demo onto the google app engine
as a more complete service when
my life calms down a bit.
- How to specify name in Django mail?
- Why does Django South require a default value when removing a field?
- Apache mod_wsgi error: Forbidden You don't have permission to access / on this server
- Django: I get a [relation "auth_group" does not exist] error after syncdb
If you’d like to look at some source for integrating Twisted and Django, have a look at Yardbird.
- Django logging requests
- Django url patterns with 2 parameters
- Access Django devserver from another machine same network
- Django how to override clean() method in a subclass of custom form?
- Advanced Django Template Logic