Added code to prevent the use of DebugMiddleware in multi-process environments.

Fixes #80
This commit is contained in:
Ryan Petrello
2012-03-17 15:52:16 -04:00
parent 8af6a4a60c
commit 87e8f87e3b
2 changed files with 25 additions and 0 deletions

View File

@@ -121,6 +121,9 @@ class DebugMiddleware(object):
self.app = app
def __call__(self, environ, start_response):
assert not environ['wsgi.multiprocess'], (
"The EvalException middleware is not usable in a "
"multi-process environment")
try:
return self.app(environ, start_response)
except:

View File

@@ -23,3 +23,25 @@ class TestDebugMiddleware(TestCase):
r = self.app.get('/error', expect_errors=True)
assert r.status_int == 400
assert 'AssertionError' in r.body
def test_middleware_complains_in_multi_process_environment(self):
class MultiProcessApp(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
environ['wsgi.multiprocess'] = True
return self.app(environ, start_response)
def conditional_error_app(environ, start_response):
start_response("200 OK", [('Content-type', 'text/plain')])
return ['Hello, World!']
app = TestApp(MultiProcessApp(DebugMiddleware(conditional_error_app)))
self.assertRaises(
AssertionError,
app.get,
'/'
)