return base + static_url_prefix + path
def async_callback(self, callback, *args, **kwargs):
- """Wrap callbacks with this if they are used on asynchronous requests.
+ """Obsolete - catches exceptions from the wrapped function.
- Catches exceptions and properly finishes the request.
+ This function is unnecessary since Tornado 1.1.
"""
if callback is None:
return None
def get(self):
http = tornado.httpclient.AsyncHTTPClient()
http.fetch("http://friendfeed-api.com/v2/feed/bret",
- callback=self.async_callback(self.on_response))
+ callback=self.on_response)
def on_response(self, response):
if response.error: raise tornado.web.HTTPError(500)
eventually calls `on_response()`, the request is still open, and the response
is finally flushed to the client with the call to `self.finish()`.
-If you make calls to asynchronous library functions that require a callback
-(like the HTTP `fetch` function above), you should always wrap your
-callbacks with `self.async_callback`. This simple wrapper ensures that if
-your callback function raises an exception or has a programming error,
-a proper HTTP error response will be sent to the browser, and the connection
-will be properly closed.
-
For a more advanced asynchronous example, take a look at the `chat` example
application, which implements an AJAX chat room using
[long polling](http://en.wikipedia.org/wiki/Push_technology#Long_polling).
@tornado.web.asynchronous
def get(self):
if self.get_argument("openid.mode", None):
- self.get_authenticated_user(self.async_callback(self._on_auth))
+ self.get_authenticated_user(self._on_auth)
return
self.authenticate_redirect()