Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow prepare to be async

  • Loading branch information...
commit 74d8431eeb564bd7ba102e74c02043803fcf1d47 1 parent 20deb5c
@acasajus authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 tornado/web.py
View
17 tornado/web.py
@@ -112,6 +112,8 @@ def __init__(self, application, request, **kwargs):
self._headers_written = False
self._finished = False
self._auto_finish = True
+ self._prepared = False
+ self._auto_run = True
self._transforms = None # will be set in _execute
self.ui = ObjectDict((n, self._ui_method(m)) for n, m in
application.ui_methods.iteritems())
@@ -1057,6 +1059,16 @@ def _execute(self, transforms, *args, **kwargs):
self.application.settings.get("xsrf_cookies"):
self.check_xsrf_cookie()
self.prepare()
+ self._prepared = True
+ self._method_args = ( args, kwargs )
+ if self._auto_run:
+ self.end_prepare()
+ except Exception, e:
+ self._handle_request_exception(e)
+
+ def _end_prepare( self ):
+ try:
+ args, kwargs = self._method_args
if not self._finished:
args = [self.decode_argument(arg) for arg in args]
kwargs = dict((k, self.decode_argument(v, name=k))
@@ -1156,7 +1168,10 @@ def _on_download(self, response):
def wrapper(self, *args, **kwargs):
if self.application._wsgi:
raise Exception("@asynchronous is not supported for WSGI apps")
- self._auto_finish = False
+ if not self._prepared:
+ self._auto_run = False
+ else:
+ self._auto_finish = False
with stack_context.ExceptionStackContext(
self._stack_context_handle_exception):
return method(self, *args, **kwargs)
Please sign in to comment.
Something went wrong with that request. Please try again.