[Twisted-web] twisted.web.wsgi usage example
Waldemar Osuch
waldemar.osuch at gmail.com
Tue Dec 9 00:38:01 EST 2008
Hi,
I'm trying to come up with an example on how to use the spanking new
twisted.web.wsgi
module. Here it is. Any comments?
8<--------------------------------------------------------------------------------------------
from twisted.internet import reactor
from twisted.application import service, internet
from twisted.web import server, static, wsgi
from twisted.python import threadpool
def wsgi_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return ['Hello from twisted.web.wsgi']
class WSGIService(service.Service):
def __init__(self, minPoolSize=5, maxPoolSize=20):
self.pool = threadpool.ThreadPool(minPoolSize, maxPoolSize)
def startService(self):
self.pool.start()
service.Service.startService(self)
def stopService(self):
self.pool.stop()
service.Service.stopService(self)
application = service.Application('wsgi')
root = static.File("www/documents")
site = server.Site(root)
internet.TCPServer(8080, site).setServiceParent(application)
serv = WSGIService()
root.putChild('wsgi', wsgi.WSGIResource(reactor, serv.pool, wsgi_app))
serv.setServiceParent(application)
More information about the Twisted-web
mailing list