Skip to content

Commit

Permalink
Merge pull request #1300 from arihantagarwal/arihant
Browse files Browse the repository at this point in the history
Changed 'return' to 'raise gen.Return()' to fix Issue #1292
  • Loading branch information
bdarnell committed Jan 10, 2015
2 parents 32e82f8 + e10e16f commit 7b82e98
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/guide/async.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 7b82e98

Please sign in to comment.