Ticket #4019 enhancement closed fixed
t.web.wsgi.WSGIResource - WSGI application error handling
| Reported by: | osuchw | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | web | Keywords: | |
| Cc: | exarkun, therve | Branch: |
branches/wsgi-error-handling-4019
(diff, github, buildbot, log) |
| Author: | exarkun | Launchpad Bug: |
Description
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 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
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
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)
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

