t.web.wsgi.WSGIResource - WSGI application error handling

[email protected] Sun, 13 Sep 2009 17:06:29 -0000
Newsgroups gmane.comp.python.twisted.bugs
Message-ID <[email protected]>
New submission from osuchw <[email protected]>:

Currently if there is an unhandled error in a WSGI application the WSGIResource will log the traceback but the request does not finish leaving the client spinning its wheels forever.

According to [http://www.python.org/dev/peps/pep-0333/#error-handling PEP-333] it is the application responsibility to handle all the errors but it would be nice if WSGIResource returned 500 in such a case.

I did a quick check and it looks like web2.WSGIResource, mod_wsgi and cherrypy do return 500, making the twisted.web version the odd man out.

To demonstrate here are runnable examples.
The t.web version
{{{
#!python
from twisted.web import server
from twisted.web.wsgi import WSGIResource
from twisted.python.threadpool import ThreadPool
from twisted.internet import reactor
from twisted.application import service, strports

wsgiThreadPool = ThreadPool()
wsgiThreadPool.start()

reactor.addSystemEventTrigger('after', 'shutdown', wsgiThreadPool.stop)

def application(environ, start_response):
    1/0
    start_response('200 OK', [('Content-type','text/plain')])
    return ['Hello World!']

wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, application)

application = service.Application('Twisted.web.wsgi Hello World Example')
server = strports.service('tcp:8080', server.Site(wsgiAppAsResource))
server.setServiceParent(application)
}}}

and t.web2 version
{{{
#!python
from twisted.web2 import server, channel
from twisted.web2.wsgi import WSGIResource
from twisted.application import service, strports

def application(environ, start_response):
    1/0
    start_response('200 OK', [('Content-type','text/plain')])
    return ['Hello World!']

wsgiAppAsResource = WSGIResource(application)

application = service.Application('Twisted.web2.wsgi Hello World Example')
server = strports.service('tcp:8080', channel.HTTPFactory(server.Site(wsgiAppAsResource)))
server.setServiceParent(application)
}}}


----------
Type     : enhancement
Component: web
Keywords : 
Priority : normal
Nosy     : 
----------
http://twistedmatrix.com/trac/ticket/4019