From e10e16fc7e1400f2fa8ad4a88f644431960f4ad5 Mon Sep 17 00:00:00 2001 From: Arihant Agarwal Date: Sat, 10 Jan 2015 11:32:24 +0530 Subject: [PATCH] Changed 'return' to 'raise gen.Return()' to fix Issue #1292, explanation added. --- docs/guide/async.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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. -- 2.47.2