From: Arihant Agarwal Date: Sat, 10 Jan 2015 06:02:24 +0000 (+0530) Subject: Changed 'return' to 'raise gen.Return()' to fix Issue #1292, explanation added. X-Git-Tag: v4.1.0b1~46^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1300%2Fhead;p=thirdparty%2Ftornado.git Changed 'return' to 'raise gen.Return()' to fix Issue #1292, explanation added. --- diff --git a/docs/guide/async.rst b/docs/guide/async.rst index 8d5f27c6a..67b702dac 100644 --- a/docs/guide/async.rst +++ b/docs/guide/async.rst @@ -108,4 +108,6 @@ the original synchronous version:: def fetch_coroutine(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) - return response.body + raise gen.Return(response.body) + +The statement ``raise gen.Return(response.body)`` is an artifact of Python 2, in which generators aren't allowed to return values. To overcome this, Tornado coroutines raise a special kind of exception called a ``Return``. The coroutine catches this exception and treats it like a returned value. In Python 3, a ``return response.body`` achieves the same result.