diff --git a/pecan/debug.py b/pecan/debug.py index eacd5b6..1c4a8c8 100644 --- a/pecan/debug.py +++ b/pecan/debug.py @@ -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: diff --git a/pecan/tests/test_commands.py b/pecan/tests/test_commands.py index 5d390d8..d7bebd8 100644 --- a/pecan/tests/test_commands.py +++ b/pecan/tests/test_commands.py @@ -26,8 +26,11 @@ class TestCommandRunner(unittest.TestCase): def test_run(self): from pecan.commands import CommandRunner runner = CommandRunner() - with self.assertRaises(RuntimeError): - runner.run(['serve', 'missing_file.py']) + self.assertRaises( + RuntimeError, + runner.run, + ['serve', 'missing_file.py'] + ) class TestCreateCommand(unittest.TestCase): diff --git a/pecan/tests/test_debug.py b/pecan/tests/test_debug.py index 468ae0a..c5cbc6e 100644 --- a/pecan/tests/test_debug.py +++ b/pecan/tests/test_debug.py @@ -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, + '/' + )