5 Apr 2006 20:27
Twisted and WSGI...
m h <sesquile <at> gmail.com>
2006-04-05 18:27:30 GMT
2006-04-05 18:27:30 GMT
Hi Folks- I'm new to this list. (Am beginning to think more about learning twisted... for the third time ;) ). I've got a question for you all and hope that you don't take it the wrong way. It's not meant to be flame bait. As WSGI is going into python 2.5, I was wondering what the general consensus is among twisted web devs about it? Does the WSGI model map well into twisted's asynchronous model? Does twisted already have everything it needs, so WSGI doesn't bring much to the table? It appears that as AJAX becomes more popular then the asynchronous model might scale better with many small requests. Say I have a WSGI app and I want to port it to twisted. How easy is that? (I know there is a twisted wsgi module) Do I just need to wrap some logic in deferreds? Are any twisted people using WSGI? Again, I'm just interested in hearing your constructive thoughts. Google didn't turn up much on the subject. thanks, -matt
.
>Which reminds me -- I started doing this in Paste, but got bogged down in
>all the setup and imports I didn't understand, and then subscribed here and
>never followed up. Can someone provide an example of a simple function that
>would look like:
Taking this approach restricts your deployment to be web-only, which eliminates a substantial advantage
of Twisted. It isn't hard to implement, though:
from twisted.web2 import server, wsgi
from twisted.web2.channel import http
from twisted.internet import reactor
>def serve_with_twisted(hosts, wsgi_app, **kw):
> """Serve wsgi_app indefinitely
>
> hosts is a list of 'address:port', and wsgi_app is a
> WSGI application. **kw is... whatever other interesting things
> you might want to use to configure a Twisted server
> """
factory = http.HTTPFactory(server.Site(wsgi.WSGIResource(app)))
for hostportpair in hosts:
host, portstr = hostportpair.split(':')
port = int(portstr)
reactor.listenTCP(port, factory, interface=host)
reactor.run()
This is completely untested, but it should at least get you going in the right direction.
RSS Feed