Skip to content

Commit

Permalink
Improve registry manager streaming to cope with WSGI server that read…
Browse files Browse the repository at this point in the history
… the output like gevent-socketio
  • Loading branch information
amol- committed Oct 9, 2013
1 parent e027037 commit f3aa239
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tg/configuration/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def __init__(self, minimal=False, root_controller=None):
self.prefer_toscawidgets2 = False
self.use_dotted_templatenames = not minimal
self.handle_error_page = not minimal
self.registry_streaming = True

self.use_sessions = not minimal
self.i18n_enabled = not minimal
Expand Down Expand Up @@ -1300,7 +1301,7 @@ def make_base_app(global_conf=None, wrap_app=None, full_stack=False, **app_conf)
app = self.add_error_middleware(global_conf, app)

# Establish the registry for this application
app = RegistryManager(app, streaming=True,
app = RegistryManager(app, streaming=config.get('registry_streaming', True),
preserve_exceptions=asbool(global_conf.get('debug')))

# Place the debuggers after the registry so that we
Expand Down
22 changes: 13 additions & 9 deletions tg/support/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ def __call__(self, environ, start_response):
app_iter = None
reg = environ.setdefault('paste.registry', Registry(self.preserve_exceptions))
reg.prepare()
if self.streaming:
return self.streaming_iter(reg, environ, start_response)

try:
app_iter = self.application(environ, start_response)
Expand All @@ -252,19 +250,25 @@ def __call__(self, environ, start_response):
reg.cleanup()
raise
else:
reg.cleanup()
# If we are streaming streaming_iter will cleanup things for us
if not self.streaming:
reg.cleanup()

if self.streaming:
return self.streaming_iter(reg, app_iter)

return app_iter

def streaming_iter(self, reg, environ, start_response):
def streaming_iter(self, reg, data):
try:
for item in self.application(environ, start_response):
yield item
for chunk in data:
yield chunk
except:
reg.preserve()
reg.cleanup()
raise
else:
finally:
if hasattr(data, 'close'):
data.close()
reg.cleanup()

class DispatchingConfig(StackedObjectProxy):
Expand Down Expand Up @@ -336,4 +340,4 @@ def _current_obj(self):
raise AttributeError(
"No configuration has been registered for this process "
"or thread")
current = current_conf = _current_obj
current = current_conf = _current_obj

0 comments on commit f3aa239

Please sign in to comment.